From 3891b078587966db53aa044b26694d412da4f059 Mon Sep 17 00:00:00 2001 From: Srujana Sadhu Date: Thu, 13 Nov 2025 19:46:28 +0530 Subject: [PATCH] =?UTF-8?q?Add=20maths/factorial.c=20=E2=80=94=20simple=20?= =?UTF-8?q?factorial=20program=20in=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maths/factorial.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 maths/factorial.c diff --git a/maths/factorial.c b/maths/factorial.c new file mode 100644 index 0000000000..b7e8014abb --- /dev/null +++ b/maths/factorial.c @@ -0,0 +1,23 @@ +– +#include + +int main(void) { + long long n; + printf("Enter a non-negative integer: "); + if (scanf("%lld", &n) != 1) { + printf("Invalid input\n"); + return 1; + } + if (n < 0) { + printf("Factorial is not defined for negative numbers.\n"); + return 1; + } + + long long result = 1; + for (long long i = 2; i <= n; ++i) { + result *= i; + } + + printf("%lld! = %lld\n", n, result); + return 0; +}