Menu

Add Topic

Forum

waiting answer January 16, 2021

C Program to Find HCF of Numbers

Answers
January 16, 2021

Program Description: gcd of two numbers in c

GCD or greatest common divisor of two integers is the largest positive integer that divides each (or both) of the integers. 

    #include <stdio.h>
    int main()
    {
        int num1, num2;

        printf("Enter two integer numbers: ");
        scanf("%d %d",&num1,&num2);

        num1 = ( num1 > 0) ? num1 : -num1;
        num2 = ( num2 > 0) ? num2 : -num2;

        while(num1!=num2)
        {
            if(num1 > num2){
                num1 -= num2;
            }else{
                num2 -= num1;
            } 
        }
        printf("GCD of the entered integer numbers are %d",num1);
        return 0;
    }

OUTPUT

        Enter two integer numbers: 5 5
        GCD of the entered integer numbers are 5

0 0

Please Login to Post the answer

Leave an Answer