Monday, July 31, 2017

Find HCF in C

#include<stdio.h>
int hcf(int a,int b,int c)
{
    if(a%c==0 && b%c==0)
    return c;
    hcf(a,b,c-1);
}
void main()
{
    int h,x,y;
    printf("Enter two numbers x and y : ");
    scanf("%d%d",&x,&y);
    if(x>y)
    {
        h=hcf(x,y,y);
    }
    else
    {
        h=hcf(y,x,x);
    }
    printf("The HCF of the entered number is : %d",h);
    getch();
}

0 comments:

Post a Comment