Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int resta (int a, int b){
- int result (0),tmp(b);
- if (a<b){b=a;a=tmp;}//...para un valor absoluto .... ;)
- while (b + result < a) result ++;
- return result ;
- }
- int main(){
- //Solo funciona para valores de a>b , asi que busco el valor absoluto
- for (auto a=1;a<10;a++){
- for (auto b=1;b<10;b++){
- cout <<"resta "<<a<<" - "<<b <<"="<<resta(a,b)<<endl;;
- }
- }
- return 0;
- }
- /*restar dos numeros sin usar el operador "-"
- pista: tres variables,un bucle while
- Complemento a 9
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement