Compute the factorial (n!) for p. - CSharp System

CSharp examples for System:Math Number

Description

Compute the factorial (n!) for p.

Demo Code

// Licensed under the Apache License, Version 2.0 (the "License");
using System;//from w w w.  j a  va  2s . c o m

public class Main{
        /// <summary>
        /// Compute the factorial (n!) for p.
        /// </summary>
        /// <param name="p">The number to compute the factorial for.</param>
        /// <returns>The factorial.</returns>
        public static double Factorial(int p)
        {
            double result = 1.0;

            for (int i = 1; i <= p; i++)
            {
                result *= (double)i;
            }

            return result;
        }
}

Related Tutorials