Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int nwd(int a, int b)
- {
- if (a < 0)
- a = -a;
- if (b < 0)
- b = -b;
- if (a * b == 0)
- return 0;
- while (a != b)
- {
- if (a > b)
- a -= b;
- if (b > a)
- b -= a;
- }
- return a;
- }
- int nww(int a, int b)
- {
- return a * b / nwd(a, b);
- }
- int main()
- {
- cout << "Podaj dwie liczby calkowite: ";
- int a, b;
- cin >> a >> b;
- int wynik = nwd(a, b);
- if (wynik != 0)
- cout << "Najwiekszy wspolny dzielnik " << a << " i " << b << " wynosi " << wynik << ", a najmniejsza wspolna wielokrotnosc " << nww(a, b) << ".\n" << endl;
- else
- cout << "Podane liczby nie maja wspolnych dzielnikow, a najmniejsza wspolna wielokrotnosc wynosi 0.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement