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 →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!