Find the Factorial of a Number: C
This video tutorial illustrates finding factorial of a given number using C programming.
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n.
Ex:
if user enters 5, then the factorial is 1 * 2 * 3 * 4 * 5 i.e., factorial = 120
This logic must be handled with a c program.
Full Source Code
#include
#include
void main()
{
int num, i, fact = 1;
clrscr();
printf("Enter a number\n");
scanf("%d", &num);
for( i = 1; i
Here the for loop stars from 1 and not 0. As anything multiplied by 0 would also be zero.
Note: Factorial of 0 is 1. i.e., 0! = 1
fact *= i; is the compact representation of fact = fact * i;
Video Tutorial: Factorial in c
YouTube Link: https://www.youtube.com/watch?v=PYLaSrO84nU [Watch the Video In Full Screen.]
Output:
Enter a number
5
Factorial of 5 is 120
Also Watch/Read: Find the Factorial of a Number: C++