Math, asked by nimmaladinesh940, 1 year ago

How to find gcd programmatically in c++?

Answers

Answered by MacTavish343
0
Helloo

The largest integer which can perfectly divide two integers is known as GCD or HCF of those two numbers.

#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;

}

This process is continued until, two numbers become equal which will be HCF.

hope it helps!!
Similar questions