basics · beginner · ~15 min
Accumulate a product in a loop.
Implement long factorial_iter(int n) returning n! using a loop. factorial_iter(0) == 1; assume n >= 0.
long factorial_iter(int n) {
/* TODO */
return 1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.