Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- unsigned nwd(unsigned x, unsigned y)
- {
- if(x * y == 0)
- return 0;
- while(x != y)
- {
- if(x > y)
- x -= y; // a = a - b;
- else
- y -= x;
- }
- return x;
- }
- unsigned nww(unsigned x, unsigned y)
- {
- if(x * y == 0)
- return 0;
- return x * y / nwd(x,y);
- }
- int main()
- {
- cout << "Prosze podac dwie liczby naturalne: ";
- unsigned a, b;
- cin >> a >> b;
- cout << "Najwiekszym wspolnym dzielnikiem podanych liczb jest " << nwd(a,b) << endl;
- cout << "Najmniejsza wspolna wielokrotnoscia podanych liczb jest " << nww(a,b) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement