Write a C++ Program to Find G.C.D Using Recursion

C++ Program to Find H.C.F Using Recursion

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Find H.C.F Using Recursion
C++ Program to Find H.C.F Using Recursion

Write a C++ Program to Find H.C.F Using Recursion

PROGRAM:C++ Program to Find HCF Recursion

/* C++ Program to Find HCF Using Recursion*/
#include <iostream>
using namespace std;

int hcf(int n1, int n2);

int main()
{
   int n1, n2;

   cout << "Enter two positive integers: ";
   cin >> n1 >> n2;

   cout << "H.C.F of " << n1 << " & " <<  n2 << " is: " << hcf(n1, n2);

   return 0;
}

int hcf(int n1, int n2)
{
    if (n2 != 0)
       return hcf(n2, n1 % n2);
    else 
       return n1;
}

Leave a Reply

Your email address will not be published. Required fields are marked *