Programming Course in C# ¡Free!

Function factorial (iterative)

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Create an iterative (non-recursive) function to calculate the factorial of the number specified as parameter:

Console.Write ( Factorial (6) );

would display

720

Output



Solution


using System;
public class FunctionFactorialIterative
{
public static float Factorial(int number)
{
int total=1;

for (int i = 1; i <= number; i++)
total *= i;

return total;
}

public static void Main()
{
Console.Write( Factorial(12) );
}
}