Write a program to print factorial of given number

Write a program to print factorial of given number



// Write a program to get factorial of given number
// Eg:- 4! -> 24, 5!-> 120

 
#include
int main(){
int i,inp,sum=1;
printf("Enter a number:");
scanf("%d",&inp); // input from user
if(inp<0)
printf("Factorial doesn't exist\n");
else
{
for(i=1;i<=inp;i++)
sum=sum*i; // calculating factorial value
printf("Factorial value=%d\n",sum);
}
return 0;
}

No comments:

Post a Comment