MichalWalczak

Zad 17

Mar 29th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int x, y;
  7. int NWD(int a, int b){
  8.     if(a%b==0){
  9.         return b;
  10.     }
  11.     else{
  12.         while(a%b!=0){
  13.             int c;
  14.             c=a%b;
  15.             a=b;
  16.             b=c;
  17.         }
  18.         return b;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     cout << "Podaj dwie liczby, aby obliczyc NWD" << endl;
  25.     cin>>x;
  26.     cin>>y;
  27.     cout<<NWD(x,y);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment