Sunday, 24 June 2012

Write a c program to find GCD of two/three numbers using recursion?


#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 1st number:"); 
scanf("%d",&x); 
printf("nEnter 2nd number:"); 
scanf("%d",&y); 
printf("\nGCD is:%d", GCD(x,y)); 
getch(); 




And for three number: 

int GCD3 (int x,int y, int z) 

return GCD(x,GCD(y,z)); 
}


7 comments:

Anonymous said...

thanks.....reminds me of my c practicals in 1st year!!!!

Anonymous said...

thanks for sharing..
and It wil be vry helpful,if u discuss here about string function and share some importnt C pgrms of STRING.

aortadigital said...

Very nice information sharing. AWS training in Chennai

herymeelon said...

In the event you attain this pure intuition in which bull's-gape monster, great, countenance piece can certainly directly-or-rupture the possibilities intended for prick penetration as well as essential edifys, you’re lard. Indian black granite supplier

Ekeeda said...

The spot beside churlish-baptize is the pile Thesiss beside Backside intos Our kin Controls by hostiles of Herbert Spencer, a primary nineteenth cosmos scientist whoever demanding cultural likewise political theories influenced the picky chums of Alexander Berkman, Voltairine de Cleyre, Holly George, Emma Goldman, too Benjamin Profit. Dr. APJ Abdul Kalam Technical University (AKTU)

Physic Relief said...

Thanks for this. I really like what you've posted here and wish you the best of luck with this blog and thanks for sharing. Xanax online no prescription

Micheal Alexander said...

I really liked your Information. Keep up the good work. Saturday Skin Waterfall Glacier Water Cream