Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int liczba1, liczba2, a, b;
- cout << "Podaj dwie liczby: ";
- cin >> a >> b;
- if(a * b == 0)
- {
- cout << "Co najmniej jedna z podanych liczb jest rowna zero, liczby nie maja wspolnego dzielnika.\n";
- return 0;
- }
- if(a < 0)
- liczba1 = -a;
- else
- liczba1 = a;
- if(b < 0)
- liczba2 = -b;
- else
- liczba2 = b;
- while(liczba1 != liczba2)
- {
- if(liczba2 > liczba1)
- liczba2 -= liczba1;
- if(liczba1 > liczba2)
- liczba1 -= liczba2;
- }
- cout << "Najwiekszy wspolny dzielnik liczb " << a << " i " << b << " wynosi " << liczba1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment