Posts

Showing posts from July 7, 2014

Find factorial of a given number using the recursive function method in C

Image
Write a program to find factorial of a given number using the recursive function method in C Hints: Factorial ! Example: 4! is shorthand for 4 x 3 x 2 x 1 The factorial function (symbol: ! ) means to multiply a series of descending natural numbers. Examples: 4! = 4 × 3 × 2 × 1 = 24 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040 1! = 1 Source Code: #include<stdio.h> //function declaration before the main int factorial(int n); //main function of the program int main() {     int n;     scanf("%d",&n);     //call function and print the final value at a time     printf("%d", factorial(n));     return 0; } int factorial(int n) {     if(n!=1)      return n*factorial(n-1); }