fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int NWD(int a, int b)
  6. {
  7. int p;
  8. if(a<b)
  9. swap(a,b);
  10.  
  11. for(int d=a; d; d--)
  12. if (a%d==0 && b%d==0) return d;
  13. }
  14.  
  15. int main()
  16. {
  17. int a, b;
  18. cout << "Podaj liczbe a: "; cin>>a;
  19. cout << "Podaj liczbe b: "; cin>>b;
  20. cout << "\nNWD(" << a << ", " << b << ") = ";
  21. cout << NWD(a,b) << endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 5320KB
stdin
35
7
stdout
Podaj liczbe a: Podaj liczbe b: 
NWD(35, 7) = 7