Overview:
In this article First of all, I want to introduce you with Numbers. Then I will explain What is Factorial? Furthermore, I will demonstrate and write logic for the factorial of a number. Moreover, I would like to explain How to find factorial of a number? After all, I will show a C program to find factorial of a number with output.
Table of contents:
- What is a Number?
- What is Factorial?
- Demonstration of factorial of a number
- How to find the Factorial of a number?
- C program to find factorial of a number
- Conclusion
What is a Number?
Number is an object that uses digits to perform mathematical task. Calculus that is a branch of mathematics included many numbers such as integer, whole number, real number, and imaginary numbers so on. Here, I will discuss about number to perform arithmetic addition operation. Moreover, Number is a combination of digits, some symbols and decimal point. For instance, 127.23 is a rational number.
What is Factorial?
The product of an integer and all the integers below it is known as factorial of that integer.
For examples,
factorial four (4!) = 24.
The Factorial of a negative number doesn't exist.
Factorial is represented by '!', so five factorial is written as (5!), n factorial as (n!).
Also, n! = n*(n-1)*(n-2)*(n-3)...3.2.1 and zero factorial is defined as one, i.e., 0! = 1.
Some other factorials examples are as follows:
0! = 1
1! = 1
2! = 1*2 =2
3! = 1*2*3 = 6
4! = 1*2*3*4 =24
5! = 1*2*3*4*5 = 120
The factorial of a positive number n is given by:
The factorial of n (n!) = 1 * 2 * 3 * 4....n
The factorial of a negative number n is not possible.
The factorial of 0 is always 1.
Demonstration of factorial of a number
How to find the Factorial of a number?
- Step 1: Take a variables as n.
- Step 2: Then, multiply the each digits within the range from 1 to that variable.
C program to find factorial of a number
#include int main() { int n, i; unsigned long long fact = 1; printf("Enter an integer: "); scanf("%d", &n); // shows error if the user enters a negative integer if (n < 0) printf("Error! Factorial of a negative number doesn't exist."); else { for (i = 1; i <= n; ++i) { fact *= i; } printf("The Factorial of %d = %llu", n, fact); } return 0; }
The output of the Program:
The Factorial of 6 = 720
Conclusion:
This Program store an integer into the int datatype. After the successful execution the factorial of this number is shown as a output.
The factorial of a positive number n is given by:
The factorial of n (n!) = 1 * 2 * 3 * 4....n
In this program we will find the factorial of a number where the number should be entered by the user. Factorial is sequence of a number whose multiply all previous number.