This C program, using recursion, finds the GCD of the two numbers entered by the user. The user enters two numbers by using a space in between them or by pressing enter after each input.
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to find GCD of given Numbers using Recursion
int gcd(int, int);
int a, b, result;
printf("Enter the two numbers to find their GCD: ");
scanf("%d%d", &a, &b);
result = gcd(a, b);
printf("The GCD of %d and %d is %d.\n", a, b, result);
int gcd(int a, int b)
while (a != b)
if (a > b)
return gcd(a - b, b);
return gcd(a, b - a);
$ gcc gcd_recr.c -o gcd_recr $ a.out Enter the two numbers to find their GCD: 100 70 The GCD of 100 and 70 is 10.
Sanfoundry Global Education & Learning Series – 1000 C Programs.
If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.
« Prev Page - C Program to Implement a Doubly Linked List & provide Insertion, Deletion & Display Operations