Program to Find HCF Using C Program

Program to Find HCF Using C Program

#include
#include
int hcf(int , int );
void main()
{
int a,b,c;
char ch;
do{

clrscr();
printf("\n Enter 1st no:");
scanf("%d",&a);
printf("\n enter 2nd no:");
scanf("%d",&b);
c=hcf(a,b);
printf(" \n <%d> and <%d> HCF value [%d]",a,b,c);
printf(" \n Continue (Y/N) :");
ch=getch();
}while(ch=='y'||ch=='Y');
}
int hcf(int x,int y)
{
int b,s,r;

if(x>y)
{
b=x;
s=y;
}
else
{
b=y;
s=x;
}
r=b%s;
while(r!=0)
{
b=s;
s=r;
r=b%s;
}
return s;
}




No comments:

Post a Comment