Write a program to calculate factorial of a number . Number being entered by user.
In this post we shall learn how to calculate factorial of a number through a program written in c
In this program user will enter a number (integer value) and program will display the corresponding factorial of the entered number.
As we know the factorial of n is = n(n-1)(n-2)(n-3).........3.2.1.
The factorial of 5 is = 120
Do not forget to subscribe me for latest update on my blog , follow me and grow your knowledge. thank you
In this post we shall learn how to calculate factorial of a number through a program written in c
In this program user will enter a number (integer value) and program will display the corresponding factorial of the entered number.
As we know the factorial of n is = n(n-1)(n-2)(n-3).........3.2.1.
now see the program
#include<stdio.h>
#include<conio.h>
int factorial(int);
int main()
{
int number,result;
printf("Enter a number\t");
scanf("%d",&number);
result = factorial(number);
printf("\n The factorial of %d is = %d",number,result);
}
int factorial(int n)
{
if(n == 0 || n == 1)
{
return(1);
}
else
{
return(n*factorial(n-1));
}
}
Output:
Enter a number 5The factorial of 5 is = 120
Do not forget to subscribe me for latest update on my blog , follow me and grow your knowledge. thank you
0 comments:
Post a Comment