Created
July 13, 2019 04:48
-
-
Save Arlus/029416913b074843b00bf2288ee694b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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