commit 075d999cc128548dfc316427e468cd5c681fa6af
parent 6dfb9358cf877ce7c8afca7bc1678eab64062e1d
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Tue, 7 Oct 2025 12:40:41 +0530
new problem 6
Diffstat:
1 file changed, 38 insertions(+), 0 deletions(-)
diff --git a/letusc/lucproblem006.c b/letusc/lucproblem006.c
@@ -0,0 +1,37 @@
+/* Write a program to find the factorial value of any number entered
+through the keyboard. */
+/* Author - Amit Dutta, Date - 07th OCT, 2025 */
+/* Let Us C, Chap - 5, Page - 84, Problem 5.2 */
+
+#include <stdio.h>
+int main()
+{
+ int num, i = 1;
+ long long fact = 1;
+ printf("Enter the number : ");
+ // checking if the input is valid or not
+ if (scanf("%d", &num) != 1)
+ {
+ printf("\nPlease enter a number.");
+ return 1;
+ }
+ // result for the negetive input
+ if (num < 0)
+ {
+ printf("\nFactorial of %d : Undefined", num);
+ return 1;
+ }
+ // Hard codded result for input '0' (zero)
+ if (num == 0)
+ {
+ printf("\nFactorial of 0 : 1");
+ return 0;
+ }
+ // calculating result
+ while (i <= num) {
+ fact = fact * i;
+ i++;
+ }
+ printf("\nFactorial of %d : %d", num, fact);
+ return 0;
+}+
\ No newline at end of file