Here in this program, we will code to calculate the factorial of a number entered by the user. Read on Factorial Program in C.
What is a factorial?
It is a mathematic concept mostly used in permutation, combination, and probability, its symbol is (!). In simple words, a factorial says multiply all whole numbers from our chosen number down to 1. For example, if we say 5 factorials in math it would be represented by 5! and evaluated by 5*4*3*2*1 = 120. By convention, the 0! is equal to 1.
Use/Application of Factorial
- In recursion we use Factorial
- In permutation
- In combination
- In probability distribution
C statements we will use in the program:
- For loop
- * (multiplication arithmetic operator)
Factorial Program in C Language
#include<stdio.h> #include<conio.h> void main() { long num, i,fact=1; clrscr(); printf("Enter a number:"); scanf("%ld",&num); for(i=num; i>=1; i--) { fact*=i; } printf("The factorial of the number %ld is %ld",num,fact); getch(); }
Output:
Enter a number:10 The factorial of the number 10 is 3628800
People are also reading:
- WAP in C++ & Python to Calculate Compound Interest
- WAP to display a message on screen
- WAP to calculate the sum of two numbers
- WAP in C++ & Python to calculate the size of each data types
- WAP to find the average of list of numbers entered by the user
- WAP in C++ & Python that calculate the average marks of 5 subjects
- WAP to find the divisors of a positive Integer
- WAP in C++ & Python for Armstrong Number
- WAP to find the greatest number among the three numbers
- WAP to print the 1 to 10 Multiples of a Number
Leave a Comment on this Post