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