Advertisement
MeehoweCK

Untitled

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