➤ FACTORIAL NUMBER -
The factorial of a non-negative integer `n` is the product of all
positive integers from 1 to `n`. It is denoted by `n!`.
The factorial of 0 is defined to be 1.
Mathematically, factorial is defined as:
- n! = 1 * 2 * 3 * ... * (n-2) * (n-1) * n
For example:
- 0! = 1
- 1! = 1
- 2! = 2 * 1 = 2
- 3! = 3 * 2 * 1 = 6
- 4! = 4 * 3 * 2 * 1 = 24
- 5! = 5 * 4 * 3 * 2 * 1 = 120
➤ Program To Print Factorial Number Using C Languages .
#include <stdio.h>
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
int num, result;
// user place any non negative number
printf("Enter a non-negative integer: ");
scanf("%d", &num);
if (num < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
result = factorial(num);
printf("The factorial of %d is: %d\n", num, result);
}
return 0;
}
➤ OUTPUT :
Enter a non-negative integer: 6
The factorial of 6 is: 720
➤ Program To Print Factorial Number Using Python Languages .
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
# Input the number for which you want to find the factorial
num = int(input("Enter a non-negative integer: "))
if num < 0:
print("Factorial is not defined for negative numbers.")
else:
result = factorial(num)
print(f"The factorial of {num} is: {result}")
➤ OUTPUT :
Enter a non-negative integer: 6
The factorial of is: 720
Program To Find The Factorial Of A Number.
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated