Advertisement
MeehoweCK

Untitled

Jul 12th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. unsigned nwd(unsigned x, unsigned y)
  6. {
  7.     if(x * y == 0)
  8.         return 0;
  9.     while(x != y)
  10.     {
  11.         if(x > y)
  12.             x -= y;         // a = a - b;
  13.         else
  14.             y -= x;
  15.     }
  16.     return x;
  17. }
  18.  
  19. int main()
  20. {
  21.     cout << "Prosze podac dwie liczby naturalne: ";
  22.     unsigned a, b;
  23.     cin >> a >> b;
  24.  
  25.     cout << "Najwiekszym wspolnym dzielnikiem podanych liczb jest " << nwd(a,b) << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement