pages

Monday, 12 April 2021

c-program to calculate the HCF of two numbers. | c-programming languages

 Q.no write a program to calculate the HCF of two number in c-programming

In this program, we are now calculate the HCF or GCD of two number by taking input from the user.

HCF is also known as GCD (greatest common divisor).

The HCF and GCD of two number is the largest integer that can exactly divide both the numbers i.e the highest common factor of two values .


#include<Stdio.h>
#include<conio.h>
main()
{
    int a,b,i;
    printf("enter the number ");
    scanf("%d %d",&a,&b);
    for(i=a<b?a:b;i>=1;i--)
        if(a%i==0&&b%i==0)
        {
            printf("hcf of the number is %d",i);
            break;
        }
    getch();
}

output: 
             
enter the two numbers a=12 and b=16
                the hcf  of the numbers are 4.



No comments:

Post a Comment