C Program to Find G.C.D using Recursion
ADVERTISEMENTS
C program to find gcd using recursion.
Example
Enter the two positive integer numbers:
90
250
G.C.D of these numbers 90 and 250 = 10
Source
// C program to find gcd using recursion
#include <stdio.h>
// function to find GCD
int gcd(int num1, int num2) {
if (num2 != 0) {
return gcd(num2, num1 % num2);
}
else {
return num1;
}
}
// It's main function of the program
int main() {
int x;
int y;
int gcd_num;
printf("Enter the two positive integer numbers:\n");
scanf("%d %d", &x, &y);
gcd_num = gcd(x, y);
printf("\nG.C.D of these numbers %d and %d = %d\n", x, y, gcd_num);
return 0;
}
Output
Enter the two positive integer numbers:
90
250
G.C.D of these numbers 90 and 250 = 10