Home » C solved programs » C basic programs

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

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

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.