Recursive GCD
In mathematics, the greatest common divisor (gcd),is the largest positive integer that divides the numbers without a remainder.In this program we calculate it recursively.
/*
http://www.ProbCOMP.com
In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf),
or highest common factor (hcf), of two or more non-zero integers,
is the largest positive integer that divides the numbers without a remainder.In this program we calculate it
recursively.
*/
#include<stdio.h>
int gcd(int n1,int n2)
{
if(n1==n2)
return n1;
else if(n1>n2)
return gcd(n1-n2,n2);
else
return gcd(n1,n2-n1);
}
void main()
{
int n1,n2;
printf("Enter 2 numbers whose gcd u need to calculcate: ");
scanf("%d%d",&n1,&n2);
int val = gcd(n1,n2);
printf("%d",val);
}
Download Program


