ccplusplus.com
Learn C, C++ Concepts
Friday, September 23, 2011
calculate factorial using recursion c
/**************************************************************** * File : calculate-factorial-using-function-recursion.c * Author : Saurabh Gupta * Desc : calculate factorial using function recursion * Source : http://saurabhgupta0527.blogspot.com/ * Created : AM 07:45 23 September 2011 ****************************************************************/ #include <stdio.h> int main() { long nNumber,f; printf("Enter a number less than 30\n"); /* * to calculate the factorial of large number download this version of program * http://saurabhgupta0527.blogspot.com/2011/09/factorial-of-large-numbers-in-c.html */ scanf("%ld",&nNumber); f = calculateFactorial(nNumber); printf("Factorial is : %ld\n",f); return 0; } int calculateFactorial(long nTempNum) { if(nTempNum == 0) { return 1; } else { return(nTempNum * calculateFactorial(nTempNum-1)); } } /* * OUTPUT * [sgupta@rhel55x86 c]$ gcc calculate-factorial-using-function-recursion.c -o calculate-factorial-using-function-recursion [sgupta@rhel55x86 c]$ ./calculate-factorial-using-function-recursion Enter a number less than 30 10 Factorial is : 3628800 [sgupta@rhel55x86 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment