PiotrJurek

Zad17

Mar 29th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int NWD(int a, int b)
  6. {
  7. while(a!=b)
  8. {
  9. if(a>b)
  10. {
  11. a=a-b;
  12. }
  13. else
  14. {
  15. b=b-a;
  16. }
  17. }
  18. return a;
  19. }
  20.  
  21. int main()
  22. {
  23. cout << NWD(54, 26) << endl;
  24. cout << NWD(97, 5) << endl;
  25. cout << NWD(512, 1024) << endl;
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment