//Program to find hcf of three numbers.
#include<stdio.h>
#include<conio.h>
int hcf(int,int);
void main()
{
int a,b,c,h;
clrscr();
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: ");
scanf("%d",&b);
printf("Enter the third number: ");
scanf("%d",&c);
h=hcf(a,b);
h=hcf(c,h);
printf("hcf of three numbers is %d",h);
getch();
}
int hcf(int a,int b)
{
int g,l,r=1;
if(a>b)
{
g=a;
l=b;
}
else
{
g=b;
l=a;
}
while(r!=0)
{
r=g%l;
if(r!=0)
{
g=l;
l=r;
}
}
return l;
}
#include<stdio.h>
#include<conio.h>
int hcf(int,int);
void main()
{
int a,b,c,h;
clrscr();
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: ");
scanf("%d",&b);
printf("Enter the third number: ");
scanf("%d",&c);
h=hcf(a,b);
h=hcf(c,h);
printf("hcf of three numbers is %d",h);
getch();
}
int hcf(int a,int b)
{
int g,l,r=1;
if(a>b)
{
g=a;
l=b;
}
else
{
g=b;
l=a;
}
while(r!=0)
{
r=g%l;
if(r!=0)
{
g=l;
l=r;
}
}
return l;
}