C++ Online Compiler
Example: C++ Program to Find GCD of Two Numbers using Recursion
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find GCD of Two Numbers using Recursion #include <iostream> using namespace std; // This function will do recursive int FindGCD(int x, int y) { if (y != 0) return FindGCD(y, x % y); else return x; } // It's the driver function int main() { int p, q; // p & q - To store the two positive numbers cout << "-----Enter the two positive integer numbers-----\n"; cin >> p >> q; cout << "\nThe GCD number of " << p << " & " << q << " is: " << FindGCD(p, q); cout << endl; return 0; }
45 90
Output
Clear
ADVERTISEMENTS