C++ Online Compiler
Example: C++ Program to Find GCD of Two Numbers using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find GCD of Two Numbers using For loop #include <iostream> using namespace std; int main() { int p, q, i, g; // p & q - To store the two positive numbers cout << "-----Enter the two positive integer numbers-----\n"; cin >> p >> q; for (i = 1; i <= p && i <= q; ++i) { if (p % i == 0 && q % i == 0) { g = i; } } cout << "\nThe GCD number of " << p << " & " << q << " is: " << g << "\n"; return 0; }
180 50
Output
Clear
ADVERTISEMENTS