C program to find HCF or GCD of two numbers using Recursion/Recursive call

#include <stdio.h>
#include<conio.h>
int main(){
int n1, n2;
int hcf(int n1, int n2);
clrscr();
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("H.C.F of %d and %d is %d.", n1, n2, hcf(n1,n2));
getch();
return 0;
}
int hcf(int n1, int n2){
if (n2 != 0)
return hcf(n2, n1%n2);
else
return n1;
}

No comments:

Post a Comment