Notification texts go here Contact Us Click here

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
➤ 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 (== 0)
        return 1;
    else
        return n * factorial(- 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(- 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
 

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.