Skip to content

Instantly share code, notes, and snippets.

@Arlus
Created July 13, 2019 04:48
Show Gist options
  • Save Arlus/029416913b074843b00bf2288ee694b4 to your computer and use it in GitHub Desktop.
Save Arlus/029416913b074843b00bf2288ee694b4 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment