Program for factorial

Program for factorial

Factorial of a number is consecutive multiplication of number with 1 number less upto 1.
Factorial is denoted by ! symbol.
e.g:
3! = 3*2*1 = 6

Program:

#include<stdio.h>
void main()
{
int n,i,ans=1;
printf(“Enter number of which you want factorial: ”);
scanf(“%d”,&n);
for(i=n;i>0;i--)
{
ans=ans*i;
}
printf("Factorial =%d",ans);
}

Output:





No comments:

Post a Comment