Example & Tutorial understanding programming in easy ways.

Write a program to find the factorial of the number.

Factorial:
-factorial of number is the multiplication of every integer number between 1 and that number.

Example-
factorial of 3 is 6(1*2*3)
factorial of 5 is 120(1*2*3*4*5)

program-

#include < stdio.h>
int main()
{
int n,fac=1,i;
printf("Enter Number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fac=fac*i;
}
printf("Factorial is %d",fac);
}


output-

Enter Number
5
Factorial is 120

Enter Number
3
Factorial is 6

-In this program, we take an input of the number and try to find the factorial of the number.
-We run the loop start from 1 to input number i.e. for(i=1;i< n=;i++)
-Multiply each value of i in loop ans store in 'fact' variable and that is the required answer.




Read More →