Advertisement
JosepRivaille

P42523: Màxim comú divisor recursiu

Mar 17th, 2015
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int mcd(int a, int b) { //m.c.d recursiu
  6.     if (b != 0) return mcd(b, a%b);
  7.     else return a;     
  8.     }
  9.  
  10. //Pre: Llegeix dos naturals
  11. //Post: Retorna l'mcd
  12. int main() {
  13.     int a, b;
  14.     cin >> a >> b;
  15.     cout << mcd(a, b) << endl;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement