ตัวอย่างการหาค่า Factorial
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FactorialTest { class Program { static void Main(string[] args) { for (byte i = 0; i < 10; i++) { Console.WriteLine(i+ "! = "+ Factorial(i)); } Console.ReadLine(); } static ulong Factorial(byte x) { if (x==1) { return 1; } else { return x * Factorial(--x); } } } }
ผลการรัน
0! = 0
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880