Overview:
In this article, First of all, I want to introduce you to Numbers. Then I will explain What is Factorial? Furthermore, I will demonstrate and write the logic for the factorial of a number. Moreover, I would like to explain How to find the factorial of a number? After all, I will show a C program to find the 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 the factorial of a number
- Conclusion
What is a Number?
A number is an object that uses digits to perform a mathematical task. Calculus that is a branch of mathematics included many numbers such as integers, whole numbers, real numbers, and imaginary numbers so on. Here, I will discuss numbers to perform arithmetic addition operations. Moreover, a Number is a combination of digits, some symbols, and decimal points. 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 the factorial of that integer.
For example,
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 variables as n.
- Step 2: Then, multiply each digit within the range from 1 to that variable.
C program to find the 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 in the int datatype. After the successful execution, the factorial of this number is shown as an 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. A Factorial is a sequence of numbers that multiply all previous numbers.