Advertisement
RobertDeMilo

НОД GCD Алгоритм Евклида

Jul 10th, 2024
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. НОД алгоритм Евклида с остатком от деления
  5.  
  6. int gcd(int a, int b)
  7. {
  8.     while (b != 0)
  9.     {
  10.         int c = a % b;
  11.         a = b;
  12.         b = c;
  13.     }
  14.     return a;
  15. }
  16.  
  17. int main()
  18. {
  19.     cout << gcd(624960, 49104);
  20.     //cout << gcd(49104, 624960);
  21.  
  22.     cout << 5 / 3 << endl; // 1
  23.     cout << 5 / 2.5 << endl; // 2
  24.     cout << 2.5 / 5 << endl; // 0.5
  25.  
  26.     cout << endl;
  27.  
  28.     cout << 5 % 3 << endl; // 2
  29.     cout << 5 % 5 << endl; // 0
  30.     cout << 10 % 5 << endl;// 0
  31.  
  32.     cout << endl;
  33.  
  34.     cout << 2 % 4 << endl; // 2  !!! ОСОБОЕ ВНИМАНИЕ !!!
  35.     cout << 3 % 9 << endl; // 3  !!! ОСОБОЕ ВНИМАНИЕ !!!
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement