Sunday, 5 January 2014

C Program to find hcf of two numbers

C Program to find HCF of two numbers

C Program to find hcf of two numbers. Today we will write hcf program in C.

HCF Program

#include<stdio.h>
#include<conio.h>
void gcd(int,int);
void main()
{
int a,b;
clrscr();
printf("ENTER ANY TWO NUMBER : \t");
scanf("%d %d",&a,&b);
gcd(a,b);
getch();
}
//function to calculate g.c.d
void gcd(int a,int b)
{
int m,n;
m=a;
n=b;
while(m!=n)
{
if(m>n)
{
m=m-n;
}
else
{
n=n-m;
}
}
printf("\nG.C.D OF %d & %d IS %d",a,b,m);
}

Output


FIND THE HCF OF TWO NUMBER
 

No comments:

Post a Comment