Advertisement
korpi2166

Algorytm Euklidesa

Oct 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int m=0,n=0,dzielnik=0,r=0;
  9. printf("Podaj liczby: \n");
  10. scanf("%d",&m);
  11. scanf("%d",&n);
  12.  
  13. // A
  14. while(m!=n)
  15. {
  16. if(m>n)
  17. {
  18. m=m-n;
  19. dzielnik=m;
  20. }
  21. else
  22. {
  23. n=n-m;
  24. dzielnik=n;
  25. }
  26. }
  27.  
  28. // B
  29.  
  30. /*
  31. do
  32. {
  33. r=m%n;
  34. if(r==0)
  35. {
  36. dzielnik=n;
  37. }
  38. m=n;
  39. n=r;
  40. }
  41. while(r!=0);
  42. */
  43.  
  44. printf("NWD wynosi %d",dzielnik);
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement