How to write a C Program to calculate Greatest Common Divisor using recursion in C Programming Language ?
Solution For C Program :
#include<stdio.h>
void main()
{
int gcd(int,int);
int a, b, result;
printf("\nEnter Any Two Values : ");
scanf("%d%d", &a, &b);
result = gcd(a, b);
printf("\nThe GCD of %d and %d is %d.", a, b, result);
}
int gcd(int x, int y)
{
int temp, n;
temp = x % y;
if(temp != 0)
{
n = gcd(y, temp);
return(n);
}
if(temp == 0)
return y;
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
Learn More :
Recursion
- C Program Recursion Example
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Generating Fibonacci Series Using Recursion
- C Program To Convert Decimal To Binary Using Recursion
- C Program To Calculate First Numbers Using Recursion
- C Program Finding the sum of Squares using Recursion
- Factorial Program In C Using Recursion
Calculate
- C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program To Calculate First Numbers Using Recursion
- C Program to Calculation of One Number Raised to Another
- C Program to calculate TT and Recharge Amount
- C Program to Calculate 2 numbers with 1 operation
- Un-sortiertes Array and Sortiertes Array
- C Program Calculation of Simple Interest
- C Program to Calculation of Total and Percentage
- C Program for calculation of Gross Salary
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program for statistically calculating pi using a specific scheduling policy.
- C Program that prompts the user to input a string, (whitespaces allowed)
- C Program Number of Judge and Score From Each Judge
- C Program to Calculate the mathematical expression for the first n numbers
- C Program to Calculate the price of movie tickets
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Accept n number from user, store these number into an array and calculate the average of n number
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation