Saturday, August 20, 2011

Find hcf of three numbers.

//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;
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More