WiktoriaRatajczyk

Zadanie 17

Mar 31st, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int nwd(int a, int b)
  6. {
  7.     int x;
  8.     int y;
  9.  
  10.     if (a<b) {y=a;}
  11.     else y=b;
  12.  
  13.     for(x=y; x>0;--x){
  14.         if((a%x==0)&&(b%x==0)) return x; }
  15. }
  16.  
  17. int main()
  18. {
  19.     cout<<"NWD(2,3) = "<<nwd(2,3)<<endl;
  20.     cout<<"NWD(10,15) = "<<nwd(10,15)<<endl;
  21.     cout<<"NWD(1000,104) = "<<nwd(1000,104)<<endl;
  22.     cout<<"NWD(9,81) = "<<nwd(9,81)<<endl;
  23.  
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment