Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- int main (){
- long a,b;
- cout << "Podaj pierwsza liczbe: " << endl;
- cin >> a;
- cout << "Podaj druga liczbe: " << endl;
- cin >> b;
- vector<int> reszty;
- reszty.push_back(a);reszty.push_back(b);
- //Obliczanie NWD
- for( ; reszty[reszty.size() - 1] != 0 ; ){
- reszty.push_back(reszty[reszty.size() - 2] % reszty[reszty.size() - 1]);
- }
- long nwd = reszty[reszty.size() - 2];
- //Obliczanie NWW
- long nww;
- nww = a*b / nwd;
- //Wyświetlenie wyników
- cout << "\nNajwiekszy wspolny dzielnik dla tych liczb wynosi: " << nwd << endl;
- cout << "Najmniejsza wspolna wielokrotnosc dla tych liczb wynosi: " << nww << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement