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();
}
Welcome to " way2cplusplus.blogspot.in " Objective of this blog is to implement various Computer Science Engineering Lab problems into C++ programming language. These are basically most common Lab Exercise problems based on the curriculum of engineering colleges throughout the Nation. These lab exercises are also relevant to Data structure. Simply C++ programming zone...
No comments:
Post a Comment