常用算法(C#): 計算10! 的值.
using System;
using System.Collections.Generic;
using System.Text;
namespace ExFactorial
{
class Factorial
{
public double factorial(int num)
{
switch (num)
{
case 1:
return 1;
default :
return num * factorial(num - 1);
}
}
static void Main(string[] args)
{
Console.WriteLine("輸入一個整數:");
int num=Convert.ToInt32 (Console.ReadLine());
Factorial f = new Factorial();
Console.WriteLine("{0}!的值為{1}", num, f.factorial(num));
}
}
}