File tree Expand file tree Collapse file tree 1 file changed +33
-5
lines changed
Expand file tree Collapse file tree 1 file changed +33
-5
lines changed Original file line number Diff line number Diff line change 1- # Title : Iterative factorial
2- # Topic : Basics
3- # Language : c
4- # Example : see bottom
1+ // Metadata Header (MANDATORY)
2+ // -----------------------------
3+ // Program Title: Factorial Calculation (Iterative)
4+ // Author: IamBisrutPyne
5+ // Date: 2025-10-10
6+ //
7+ // Description: Computes the factorial of a non-negative integer using an iterative approach.
8+ //
9+ // Language: C
10+ //
11+ // Time Complexity: O(n)
12+ // Space Complexity: O(1)
13+ // -----------------------------
514
6- // Iterative factorial - placeholder in c
15+ #include <stdio.h>
16+
17+ // Calculates n! iteratively. Using long long for potentially larger results.
18+ long long factorial (int n ) {
19+ if (n < 0 ) {
20+ return 0 ;
21+ }
22+ long long result = 1 ;
23+ for (int i = 2 ; i <= n ; i ++ ) {
24+ result *= i ;
25+ }
26+ return result ;
27+ }
28+
29+ int main () {
30+ int num = 10 ;
31+ printf ("Factorial of %d is: %lld\n" , num , factorial (num ));
32+ // Output: Factorial of 10 is: 3628800
33+ return 0 ;
34+ }
You can’t perform that action at this time.
0 commit comments