Advertisement
MeehoweCK

Untitled

Apr 18th, 2023
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int nwd(int a, int b)       // funkcja pobiera dwie liczby całkowite i zwraca ich największy wspólny dzielnik (lub 0)
  6. {
  7.     if(a * b == 0)
  8.         return 0;
  9.     if(a < 0)   a = -a;
  10.     if(b < 0)   b = -b;
  11.  
  12.     while(a != b)
  13.     {
  14.         if(a > b)
  15.             a -= b;
  16.         if(b > a)
  17.             b -= a;
  18.     }
  19.     return a;
  20. }
  21.  
  22. int main()
  23. {
  24.     cout << nwd(12, 18) << endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement