fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Function to compute GCD using Euclid's algorithm
  5. int gcd(int a, int b) {
  6. while (b != 0) {
  7. int temp = b;
  8. b = a % b;
  9. a = temp;
  10. }
  11. return a;
  12. }
  13.  
  14. int main() {
  15. int num1 = 31415;
  16. int num2 = 14142;
  17.  
  18. // Finding GCD
  19. int result = gcd(num1, num2);
  20.  
  21. cout << "The GCD of " << num1 << " and " << num2 << " is: " << result << endl;
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
The GCD of 31415 and 14142 is: 1