Users Online
· Guests Online: 30
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C Program to Find GCD of given Numbers using Recursion
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
*/
#include <stdio.h>
int gcd(int, int);
int main()
{
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);
}
else
{
return gcd(a, b - a);
}
}
return 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.
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
*/
#include <stdio.h>
int gcd(int, int);
int main()
{
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);
}
else
{
return gcd(a, b - a);
}
}
return 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.
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.