MarcinKrol

Zad17

Mar 24th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. //Zad17
  4.  
  5. using namespace std;
  6. int a , b;
  7. void NWD()
  8. {
  9. for(int i=a; i>=1; i--)
  10. {
  11. if(a%i==0 && b%i==0)
  12. {
  13. cout<<i<<endl;
  14. break;
  15. }
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. cout << "Podaj 2 liczby naturalne" << endl;
  22. cin >> a >> b;
  23.  
  24. if(a<0 || b<0)
  25. {
  26. cout<<"To nie jest liczba naturalna"<<endl;
  27. }
  28.  
  29. cout<<"Najwiekszy wspolny dzielnik to: ";
  30. NWD();
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment