C++Programs
The following program is to find the Highest Common Factor (HCF) of any two numbers entered by the user.
The program uses simple for loop.
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,i;
cout<<"Enter any two numbers: ";
cin>>a>>b;
for(i=a;i>=1;i--)
{
if(a%i==0&&b%i==0)
break;
}
cout<<"HCF: "<<i;
getch();
}
Output:
First Run:
Second Run:
For any queries or suggestions please comment.
No comments:
Post a Comment