C++ Online Compiler
Example: C++ Program to Find GCD of Two Numbers using Function
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find GCD of Two Numbers using Function #include <iostream> using namespace std; // This function will find the GCD number void FindGCD(int x, int y) { int gcd, i; for (i = 1; i <= x && i <= y; ++i) { if (x % i == 0 && y % i == 0) { gcd = i; } } cout << "\nThe GCD number of " << x << " & " << y << " is: " << gcd << "\n"; } // 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; FindGCD(p, q); return 0; }
45 90
Output
Clear
ADVERTISEMENTS