Header Ads Widget

Program to calculate GCD of two numbers by using recursion ..

program:-

#include<stdio.h>
int gcd(int a,int b)
{
if(a==b)
return (a);
if(a%b==0)
return (b);
if(b%a==0)
return (a);
if(a>b)
return (gcd(a%b,b));
else
return (gcd(a,b%a));
}
void main()
{
int a,b,g;
printf("Enter two number");
scanf("%d%d",&a,&b);
g=gcd(a,b);
printf("gcd is %d",g);
}



Post a Comment

0 Comments