Factorial (loop)
C++ Loops
for with accumulation
Flowchart (ISO 5807)
Source code
long fact(int n) {
long r = 1;
for (int i = 2; i <= n; i++) {
r *= i;
}
return r;
} for with accumulation
long fact(int n) {
long r = 1;
for (int i = 2; i <= n; i++) {
r *= i;
}
return r;
}