AD 1
- Back to Home »
- Technology Help »
- How to find HCF of two numbers using C language ?
Posted by : Unknown
Thursday, November 20, 2014
Actually, it is a very easy program. The only difficulty that one may have is to find a logic in making that program .
Type this code in your compiler. Then Compile and Run. I have used Dev C++.
#include<stdio.h>
int main()
{
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--)
{
if(x%i==0&&y%i==0)
{
printf("\nHCF of two number is : %d",i) ;
break;
}
}
return 0;
}
INPUT:-
Type this code in your compiler. Then Compile and Run. I have used Dev C++.
#include<stdio.h>
int main()
{
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--)
{
if(x%i==0&&y%i==0)
{
printf("\nHCF of two number is : %d",i) ;
break;
}
}
return 0;
}
INPUT:-
OUTPUT:-