by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to find out the HCF (highest common factor) using function. As declaring required variable user ask to enter the value. User made a function named “HCF”. Then using control statement if(a>b) the HCF (a,b) else (b,a) after fetching the HCF through getch(). 

In the next move user calls the function that made HCF. Here user also declare a variable named r=1. And a while condition too. While(r! =0) if the condition got true than the value must be fetch out from use of modulus operator. After that interchange the value within x, y or r. display the result on the screen.

Problem Statement:

This is C program that asks user to find out the HCF using function.

  1. Declaring the variable.
  2. Using control statement.
  3. Display result on the screen.

This is C program here user need to find out the HCF using function Method. Output of this program shown below. 


int hcf(int x,int y);
void main()
    int a,b,d;
    printf("Enter 2 Numbers : ");
           d= hcf(b,a);
           printf("HCF is= %d",d);
    int hcf(int x,int y)
       int r=1;

Calculate HCF of 2 Numbers using Functions

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.