Advertisement
sheredega

Task #13

Dec 10th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.     int first;
  8.     int second;
  9.     int range;
  10.     cout << "Enter the first number: ";
  11.     cin >> first;
  12.     cout << "Enter the second number: ";
  13.     cin >> second;
  14.     if (abs(first) > abs(second)) {
  15.         range = abs(second);
  16.     }
  17.     else {
  18.         range = abs(first);
  19.     }
  20.     int min = 1;
  21.  
  22.     for (int i = 2; i <= range; i++) {
  23.         if ((first % i) == 0 && (second % i) == 0) {
  24.             min = i;
  25.             break;
  26.         }
  27.     }
  28.     if (min == 1) {
  29.         cout << "This numbers haven`t general divider!";
  30.     }
  31.     else {
  32.         cout << "The smallest general divider is: " << min;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement