Advertisement
AntonioVillanueva

Resta sin resta

Feb 1st, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int resta (int a, int b){
  5.     int result  (0),tmp(b);
  6.     if (a<b){b=a;a=tmp;}//...para un valor absoluto .... ;)
  7.  
  8.     while (b + result < a) result ++;
  9.     return result ;
  10.    
  11. }
  12. int main(){
  13.     //Solo funciona para valores de a>b , asi que busco el valor absoluto
  14.     for (auto a=1;a<10;a++){
  15.         for (auto b=1;b<10;b++){
  16.             cout <<"resta "<<a<<" - "<<b <<"="<<resta(a,b)<<endl;;
  17.         }
  18.     }
  19.  
  20. return 0;
  21. }
  22.  
  23. /*restar dos numeros sin usar el operador "-"
  24. pista: tres variables,un bucle while
  25. Complemento a 9
  26. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement