Write a C program to find GCD using recursion.
#include <stdio.h>
#include <conio.h>
int gcd(int ,int,int);
main()
{
int a,m,n,g;
printf("\n\t\t GREATEST
COMMON DIVISOR ");
printf("\n\t\t*************************\n");
printf("\n INPUT:");
printf("\n*******\n");
printf("\n Enter the First
Number :");
scanf("%d",&m);
printf("\n Enter the Second
Number :");
scanf("%d",&n);
if(m<=n)
{
g=m;
a=gcd(m,n,g);
}
else
{
g=n;
a=gcd(n,m,g);
}
printf("\n OUTPUT:");
printf("\n********\n\n");
printf("%d",a);
getch();
}
int gcd(int m,int n,int g)
{
if((n%g)==0&&(m%g)==0)
return(g);
else
gcd(m,n,g-1);
}
0 comments:
Feel free to contact the admin for any suggestions and help.