find gcd in c 2b 2b without inbuilt function

Solutions on MaxInterview for find gcd in c 2b 2b without inbuilt function by the best coders in the world

showing results for - "find gcd in c 2b 2b without inbuilt function"
Yann
12 Jun 2019
1#include <iostream>
2using namespace std;
3
4int main()
5{
6    int n1, n2;
7
8    cout << "Enter two numbers: ";
9    cin >> n1 >> n2;
10    
11    while(n1 != n2)
12    {
13        if(n1 > n2)
14            n1 -= n2;
15        else
16            n2 -= n1;
17    }
18
19    cout << "HCF = " << n1;
20    return 0;
21}