H.C.F of Two Number In Cpp

Program:

#include <iostream.h>
#include<conio.h>

int hcf(int n1, int n2);

void main()
{
clrscr();
int n1, n2;

cout << " Enter two positive integers: \n";
cout << " Number First : ";
cin >> n1;
cout << " Number Second : ";
cin >> n2;
cout << " H.C.F of " << n1 << " & " << n2 << " is: " << hcf(n1, n2);

getch();
}

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

Output:

HCF in cpp
HCF

 

(Visited 150 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

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