Program to Find Factorial.

The factorial, symbolized by an exclamation mark (!), is a quantity defined for all integer s greater than or equal to 0.
For an integer n greater than or equal to 1, the factorial is the product of all integers less than or equal to n but greater than or equal to 1. The factorial value of 0 is defined as equal to 1. The factorial values for negative integers are not defined.
Mathematically, the formula for the factorial is as follows. If n is an integer greater than or equal to 1, then

n ! = n ( n - 1)( n - 2)( n - 3) ... (3)(2)(1)

If p = 0, then p ! = 1 by convention.

The factorial is of interest to number theorists. It often arises in probability calculations, particularly those involving combinations and permutations. The factorial also arises occasionally in calculus and physics.

Program:-

#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
   unsigned int n;
    unsigned long long factorial = 1;

    cout << "Enter a positive integer: ";
    cin >> n;

    for(int i = 1; i <=n; ++i)
    {
        factorial *= i;
    }

    cout << "Factorial of " << n << " = " << factorial;  
getch();
}

Output:-
Output of the Program to Find Factorial.
Output

Post a Comment

0 Comments