Write a program to find two number of GCD in c++

 Statement:   Find Two Numbers of GCD.

GCD stands for Greatest Common Divisor. It is a very simple program.

Input: 

Output:- 

Program:

#include <iostream>
using namespace std;

int gcd(int m, int n)
{
    if (m == n)
        return m;
    if (m > n)
        return gcd(m - n, n);
    return gcd(m, n - m);
}

int main()
{
    int m, n;
    cout << "Enter the First Number " << endl;
    cin >> m;
    cout << "Enter the Second Number" << endl;
    cin >> n;
    cout << "The GCD is " << gcd(m, n);
    return 0;
}




Post a Comment

0 Comments