Answers for "find gcd in c++ without inbuilt function"

C++
0

find gcd in c++ without inbuilt function

#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;
}
Posted by: Guest on June-19-2021

Code answers related to "find gcd in c++ without inbuilt function"

Browse Popular Code Answers by Language