The highest common factor of integers x and y is the largest integer that evenly divides both x and y.
The main points to be remember while doing this program is:
If y is equal to 0, then hcf(x,y) is x,
otherwise
hcf(x,y) is hcf(y,x%y)
The main source code of the program is given below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
int hcf(int,int); | |
int main() | |
{ | |
int a,b,gcd; | |
printf("enter two numbers to calculate hcf"); | |
scanf("%d%d",&a,&b); | |
gcd=hcf(a,b); | |
printf("greatest common divisor ids %d",gcd); | |
getch(); | |
} | |
int hcf(int x,int y) | |
{ | |
if (y!=0) | |
return hcf(y,x%y); | |
else | |
return x; | |
} | |
0 comments :
Post a Comment