Pages

Tuesday, November 10, 2015

C program to find Factorial of no.

/*  In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal ton. For example,
5! = 5  \times  4  \times  3  \times  2  \times  1 = 120.  \
The value of 0! is 1, according to the convention for an empty product.[1]  */

Program

#include<stdio.h>
void main()
{
int no,i,ans=1;
printf("Enter the no\n");
scanf("%d",&no);

for(i=1;i<=no;i++)
{
ans=ans*i;
}
printf("Factorial=%d",ans);
}

Output
Enter the no
5
Factorial=120

No comments:

Post a Comment