C program to find factorial of a number

devquora
devquora

Posted On: Dec 23, 2020

C program to find factorial of a number

 

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:

  1. What is a Number?
  2. What is Factorial?
  3. Demonstration of factorial of a number
  4. How to find the Factorial of a number?
  5. C program to find factorial of a number
  6. 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

Demo factorial

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

Demo factorial

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. 

    Related Questions

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..