Programming Code Center(PCC)
[CPP]

(PCC)::[How-to-write-CPP-Program-to-Find-GCD]::[cpp]

File Name : GCD_using_while_loop.cpp

//Example : Find GCD using while loop
#include <iostream>
using namespace std;

int main()
{
    int n1, n2;

    cout << "Enter two numbers: ";
    cin >> n1 >> n2;
    
    while(n1 != n2)
    {
        if(n1 > n2)
            n1 -= n2;
        else
            n2 -= n1;
    }

    cout << "HCF = " << n1;
    return 0;
}

//

Output :

GCD_using_while_loop.jpg