factorial

This commit is contained in:
2025-08-03 10:58:24 -04:00
parent 4c7d454690
commit 9071bdddd7
4 changed files with 147 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
int factorial(int num) {
int i; // $t1
int j; // $t2
int temp; // $t3
int sum; // $t4
temp = 1;
sum = 1;
i = 1;
while (i <= num) {
sum = 0;
j = 0;
while (j < i) {
sum += temp;
j++;
}
temp = sum;
i++;
}
return sum;
}
int main() {
printf("fac(%d) = %d\n", 6, factorial(6));
return 0;
}