In this C-program we will calculate the factorial of a number. The number will be taken from the user.color>
input:
The number(i.e : 5,6,9 etc.)output:
The factorial of the given numberCODE---->
#include
#include
{
int i,n,fact=1;
clrscr();
printf("Enter a number:-color>");
scanf("%dcolor>",&n);
if(ncolor>)
{
printf("\n%d is a negative number. Factorial of a negative number doesn't exist.color>",n);
}
if(n==0color>)
{
printf("\nThe factorial of 0 is = 0color>");
}
if(n>0color>)
{
for(i=1color>;i;i++color>)
{
fact=fact*i;
}
printf("\nThe factorial of %d is = %dcolor>",n,fact);
}
getch();
}
Notecolor>:The program of multiplication of integers upto range 'n' is also the same program of above.color>
color>