Q:

Write a C program to find HCF (Highest Common Factor) of two numbers

0

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

This program will read two integer numbers and print Highest Common Factor (HCF).

All Answers

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

Find HCF (Highest Common Factor) program in C

/*C program to find HCF of two numbers.*/
#include <stdio.h>
 
//function to find HCF of two numbers
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;
}

Output

    Enter first number: 100
    Enter second number: 40
    HCF (Highest Common Factor) of 100,40 is: 20

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

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
Write a C program to multiply two numbers using pl... >>
<< Write a C program to find area of rectangle...