Iterative Factorial

The factorial of an integer, number, greater than or equal to 0, can be calculated iteratively (nonrecursively) by using a for statement as follows:

factorial = 1;for ( unsigned int counter = number; counter >= 1; --counter )   factorial *= counter;

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.