Sunday, August 2, 2009

What is a 'c' code for finding a factorial of a number using recursive functions?

int abc(int n) {


if(n==0) {


return 1;


} else {


return n*abc(n-1);


}


}





Got it(onlykeshu@yahoo.co.in)

What is a 'c' code for finding a factorial of a number using recursive functions?
# include%26lt;stdio.h%26gt;





void main()


{


int n,a;


printf("Enter the Number");


scanf("%d",%26amp;n);


a=fact(n)


printf("Factorial is -%d",a);


}


int fact(int f)


{


if(f==0)


{


f=0;


}


elseif(f==1)


{


f=1;


}


else


{


f=f*fact(n-1);


}


return f;


}


No comments:

Post a Comment