Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Factorial in C
SUBMITTED BY:
kaushal1981
DATE:
Feb. 17, 2017, 1:45 a.m.
FORMAT:
Text only
SIZE:
519 Bytes
Raw
Download
Tweet
HITS:
945
Go to comments
Report
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1;
printf("Enter an integer: ");
scanf("%d",&n);
// show error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else
{
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus