Calculate GCD Value


#include<stdio.h>
#include<conio.h>
int gcd(int a,int b)
{
if(a<0)
 a=-a;
if(b<0)
 b=-b;
if(a==0||b==1||a==b)
return b;
if(a==1||b==0)
return a;
if(a>b)
return gcd(b,a%b);
else
return gcd(a,b%a);
}
void main()
{
int x,y;
clrscr();
printf("\nEnter the 1st Number:");
scanf("%d",&x);
printf("\nEnter the 2nd Number:");
scanf("%d",&y);
printf("\n GCD value is %d",gcd(x,y));
getch();
}                                                     

No comments:

Post a Comment

Thank you for using this blog.