Advertisement
MeehoweCK

Untitled

Aug 16th, 2022
638
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.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     unsigned a, b;
  8.     cout << "Podaj dwie liczby naturalne: ";
  9.     cin >> a >> b;
  10.  
  11.     if(a * b == 0)
  12.         cout << "Przynajmniej jedna z podanych liczb wynosi 0, wiec nie maja one wspolnego dzielnika\n";
  13.     else
  14.     {
  15.         // algorytm Euklidesa
  16.         while(a != b)
  17.         {
  18.             if(a > b)
  19.                 a -= b;
  20.             if(b > a)
  21.                 b -= a;
  22.         }
  23.         cout << "Najwiekszy wspolny dzielnik wynosi " << a << endl;
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement