Posts

Showing posts from February, 2007

C Program to Calculate Factorial of a number using Recursion

Write a program to calculate the factorial of a number. Use the concept of recursion instead of using loops. #include <stdio.h> main ( ) { int a , fact ; printf ( " \n Enter any number: " ) ; scanf ( "%d" , & a ) ; fact = rec ( a ) ; printf ( " \n Factorial Value = %d" , fact ) ; } rec ( int x ) { int f ; if ( x = = 1 ) return ( 1 ) ; else f = x * rec ( x - 1 ) ; return ( f ) ; }