Advertisement
MeehoweCK

Untitled

Jul 12th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 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. unsigned nww(unsigned x, unsigned y)
  20. {
  21.     if(x * y == 0)
  22.         return 0;
  23.     return x * y / nwd(x,y);
  24. }
  25.  
  26. int main()
  27. {
  28.     cout << "Prosze podac dwie liczby naturalne: ";
  29.     unsigned a, b;
  30.     cin >> a >> b;
  31.  
  32.     cout << "Najwiekszym wspolnym dzielnikiem podanych liczb jest " << nwd(a,b) << endl;
  33.     cout << "Najmniejsza wspolna wielokrotnoscia podanych liczb jest " << nww(a,b) << endl;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement