C++ Program to find HCF of two number.
The largest integer which is perfectly divisible to two or more numbers is known as H.C.F or G.C.D of those two numbers.There
are many ways to find the H.C.F of two numbers is C++ programming. Below code will take two integers from user and displays the H.C.F of
those two integers.This is the best way to find HCF of two numbers.
In this method, smaller
number is subtracted from larger number and that number is stored in
place of larger number. This process is continued until, two numbers
become equal which will be HCF.
Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int num1,num2;
cout<<" Find HCF of two number by-Tarun Rawat\n\n";
cout<<"Enter first number : ";
cin>>num1;
cout<<"Enter second number : ";
cin>>num2;
cout<<"HCF of "<<num1<<" & "<<num2<<" is : ";
while(num1!=num2)
{if(num1>num2)
num1-=num2;
else num2-=num1;
}
cout<<num1;
getch();
}
No comments:
Post a Comment