Monday 9 September 2013

c program to find gcd using recursion

#include<stdio.h>
#include<conio.h>
int findgcd(int m,int n)
{
if(m==0)
return n;
if(n==0)
return m;
else
return (findgcd(m,m%n));
}
void main()
{
int u,v,gcd;
clrscr();
printf("enter any two positive inegers..");
scanf("%d%d",&u,&v);
gcd=findgcd(u,v);
printf("gcd of two given no. is: %d",gcd);
getch();
}

No comments:

Post a Comment