write a program for gcd of two numbers using recursion
Answers
Answer:
In this C Program, we are reading the two integer numbers using 'a' and 'b' variable. The gcd() function is used to find the GCD of two entered integers using recursion. While loop is used to check that both the 'a' and 'b' variable values are not equal. If the condition is true then execute the loop.
Answer:
/*
* 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;
}
Explanation:
hope it helps people follow me and mark me as brainliest