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 * b == 0) {
- return 0;
- }
- if (a < 0) {
- a = -a;
- }
- if (b < 0) {
- b = -b;
- }
- while (a != b) {
- if (a > b) {
- a -= b;
- }
- if (b > a) {
- b -= a;
- }
- }
- return a;
- }
- //unsigned int nww(unsigned int a, unsigned int b) {
- // return a * b / nwd(a, b);
- //}
- int main() {
- cout << "Podaj dwie liczby naturalne: ";
- int a, b;
- cin >> a >> b;
- auto wynik{ nwd(a, b) };
- if (wynik == 0) {
- cout << a << " i " << b << " nie posiadaja wspolnego dzielnika\n";
- }
- else {
- cout << "Najwiekszy wspolny dzielnik liczb " << a << " i " << b << " wynosi " << wynik << endl;
- /*cout << "Najmniejsza wspolna wielokrotnosc tych liczb wynosi " << nww(a, b) << endl;*/
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement