Q:

C Program to find HCF (Highest Common Factor) of two numbers

0

C Program to find HCF (Highest Common Factor) of two numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 

int findHcf(int a,int b)
{
    int temp;
     
    if(a==0 || b==0)
    return 0;
    while(b!=0)
    {
        temp = a%b;
        a    = b;
        b    = temp;
    }
    return a;
}
int main()
{
    int a,b;
    int hcf;
     
    printf("Enter first number: ");
    scanf("%d",&a);
    printf("Enter second number: ");
    scanf("%d",&b);
     
    hcf=findHcf(a,b);
    printf("HCF (Highest Common Factor) of %d,%d is: %d\n",a,b,hcf);
     
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now