Lunes, Pebrero 18, 2019

"The n factorial"

In this Turbo C programming tutorial I am going to show you guys how to find a factorial of a number using "for loop". The factorial of a positive integer n is equal to 1*2*3*4...n. You will learn to calculate the factorial of a number using for loop in this example.


The factorial of a positive number n is given by:

factorial of n (n!) = 1*2*3*4...n

The factorial of a negative number doesn't exist. And, the factorial of 0 is 1, 0! = 1

This will be the example output:
Enter an integer: 10
Factorial of 10: 3628800

The program will take a positive integer from the user and computes factorial using for loop.

Since the factorial of a number may be very large, the type of factorial variable is declared as unsigned long long


If the user enters negative number, the program displays error message. 

Walang komento:

Mag-post ng isang Komento