Posts

Showing posts from August 25, 2013

HCF of two numbers using recursion

void hcf(int a,intb )
{
if(b%a = =  0)
//print the value of a
printf("%d",a);
else
hcf(b%a,a)
}


eg: if a = 15 and b=25
then
25%15 = 10 so hcf(10,15 ) will be called15%10 = 5  so hcf (5,10) will be called 10%5 = 0 so 5 will be printed 
if a=25 and b=15  then  15%25= 15 so hacf (15,25 ) will be called 25%15 = 10 so hcf(10,15 ) will be called15%10 = 5  so hcf (5,10) will be called 10%5 = 0 so 5 will be printed