diff --git a/Factorial of a number b/Factorial of a number new file mode 100644 index 0000000..f4a44e5 --- /dev/null +++ b/Factorial of a number @@ -0,0 +1,19 @@ +#include + factorial() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows 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) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + // return 0; +}