From f31eba4c5ff1dd7608497a381f6fd7eab9a5451f Mon Sep 17 00:00:00 2001 From: ayushaman4651 <73748590+ayushaman4651@users.noreply.github.com> Date: Sat, 31 Oct 2020 20:47:34 +0530 Subject: [PATCH] Create Program to find factorial of a number in C find factorial of a number in C --- Program to find factorial of a number in C | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find factorial of a number in C diff --git a/Program to find factorial of a number in C b/Program to find factorial of a number in C new file mode 100644 index 0000000..07b09ea --- /dev/null +++ b/Program to find factorial of a number in C @@ -0,0 +1,19 @@ +#include +int main() { + 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; +}