/*
Program for find GCD using recursion.
*/
#include<conio.h>
#include<stdio.h>
int findGCD(int,int);
int GCD(int,int,int);
int main()
{
clrscr();
printf("%d",findGCD(49,56));
return 0;
}
int findGCD(int firstNumber,int secondNumber)
{
return GCD(firstNumber,secondNumber,2);
}
int GCD(int firstNumber,int secondNumber,int denominator)
{
static int selected=1;
if(firstNumber%denominator==0 && secondNumber%denominator==0)
{
selected = denominator;
return GCD(firstNumber,secondNumber,denominator+1);
}
else if(denominator<=firstNumber && denominator<=secondNumber)
{
return GCD(firstNumber,secondNumber,denominator+1);
}
else
{
return selected;
}
}
No comments:
Post a Comment