Write a c program to find factorial of a number
//c program to find factorial of a number
#include <stdio.h>
int main()
{
int n, i;
unsigned long long fact =1;
printf("Enter an integer: ");
scanf("%d", &n);
//show arror if the user enters a negative integer
if(n<0)
printf("Error ! factorial of a negative number doesnt exist.");
else{
for(i=1; i<=n; ++i){
fact *= i;
}
printf("Factorial of %d= %llu", n, fact);
}
return 0;
}
This program is only use for educational purpose ,it can be helpful for Computer science background and these Computer science programs are Runs in lab.
Comments
Post a Comment