3
Please create a method which will calculate factorial of the number n. Mathematical description of this function is available on Wikipedia here: https://en.wikipedia.org/wiki/Factorial Expected result: Complete code that returns the value
C# .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Napište číslo factorialu: ");
int number = Convert.ToInt32(Console.ReadLine());
double finish = factorial(number);
Console.WriteLine(finish.ToString());
Console.ReadLine();
}
static double factorial(int number)
{
if (number == 1 || number == 0)
return 1;
double factoNmb = 1;
for(int i = number; i>=1; i--)
{
factoNmb = factoNmb * i;
}
return factoNmb;
}
}
}
Neformátovaný
Přidáno: 25.5.2016
Expirace: Neuvedeno