Advertisement
Alelluja

Untitled

Dec 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int nwd(int a, int b)
  7. {
  8.   while(a != b)
  9.   {
  10.       if(a>b)
  11.       {
  12.           a-=b;
  13.       }
  14.       else
  15.       {
  16.           b-=a;
  17.       }
  18.   }
  19.   return a;
  20. }
  21.  
  22. int nww(int a, int b)
  23. {
  24.   return (a * b)/nwd(a, b);
  25. }
  26.  
  27. int main()
  28. {
  29.   int a, b;
  30.  
  31.   cout << "Podaj A: ";
  32.   cin >> a;
  33.  
  34.   cout << "Podaj B: ";
  35.   cin >> b;
  36.  
  37.   int iNWD = nwd(a, b);
  38.   cout << "Najwiekszy wspolny dzielnik to: " << iNWD << endl;
  39.  
  40.   int iNWW = nww(a, b);
  41.   cout << "Najwiekszy wspolna wielokrotnosc to: " << iNWW;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement