Robson » Code » C++ » Factorials

 
// factorials finder v1.0
 
#include <stdio.h>
 
// work out the factorial of the specified number
int fact(int number)
{
   for (int total = 1, int a = 2; a <= number; total *= a++);
   return total;
}
 
// * example use - print factorials of numbers 1 to 10 * //
int main()
{
   for (int n = 1; n <= 10; n++)
       printf("%d=%d\n", n, fact(n));
}
 
© 2004-17 robson | cc unless stated