avr39ripe

cppTwoNumberCommonDivisor

Mar 15th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     int numA{ 0 };
  6.     int numB{ 0 };
  7.  
  8.     std::cout << "Enter number A\n";
  9.     std::cin >> numA;
  10.     std::cout << "Enter number B\n";
  11.     std::cin >> numB;
  12.  
  13.     for (int divisor{ 1 }, maxRange{ numA > numB ? numA : numB }; divisor <= maxRange; ++divisor)
  14.     {
  15.         if (numA % divisor == 0 and numB % divisor == 0)
  16.         {
  17.             std::cout << divisor << ' ';
  18.         }
  19.     }
  20.     std::cout << '\n';
  21.  
  22.     return 0;
  23. }
Add Comment
Please, Sign In to add comment