Users Online

· Guests Online: 37

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to Find the Factorial of a Number using Recursion

This C Program prints the factorial of a given number using recursion. A factorial is product of all the number from 1 to the user specified number.
Here is the source code of the C program to print the factorial of a given number. The C program is successfully compiled and run on
a Linux system. The program output is also shown below.

/*
* C Program to find factorial of a given number using recursion
*/
#include <stdio.h>

int factorial(int);

int main()
{
int num;
int result;

printf("Enter a number to find it's Factorial: ");
scanf("%d", &num);
if (num < 0)
{
printf("Factorial of negative number not possible\n");
}
else
{
result = factorial(num);
printf("The Factorial of %d is %d.\n", num, result);
}
return 0;
}
int factorial(int num)
{
if (num == 0 || num == 1)
{
return 1;
}
else
{
return(num * factorial(num - 1));
}
}

$ cc pgm5.c
$ a.out
Enter a number to find it's Factorial: 6
The Factorial of 6 is 720.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.90 seconds
10,272,674 unique visits