Advertisement
MeehoweCK

Untitled

Feb 5th, 2024
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     unsigned int a, b;
  7.     cout << "Wpisz dwie liczby naturalne: ";
  8.     cin >> a >> b;
  9.     if (a == 0 || b == 0) {
  10.         cout << "Te liczby nie posiadaja wspolnego dzielnika.\n";
  11.     }
  12.     else {
  13.         auto x{ a }, y{ b };        // automatyczne przypisanie typu zmiennej
  14.         while (x != y) {
  15.             if (x > y) {
  16.                 x -= y;
  17.             }
  18.             if (y > x) {
  19.                 y -= x;
  20.             }
  21.         }
  22.         cout << "Najwiekszym wspolnym dzielnikiem liczb " << a << " i " << b << " jest liczba " << x << ".\n";
  23.         cout << "Najmniejsza wspolna wielokrotnoscia tych liczb jest " << a * b / x << ".\n";
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement