【发布时间】:2014-12-21 14:42:53
【问题描述】:
我不能将 20 和 17 组合,程序说结果是 1。为什么?我确定我的代码是正确的,但我无法组合大数字。
using System;
namespace question
{
class beat_That
{
static int Factorial(int m)
{
int result = 1;
for (int i = 1; i <= m; i++)
{
result *= i;
}
return result;
}
static void Main(string[] args)
{
Console.WriteLine("enter number of objects in the set: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter number to be chosen: ");
int k = Convert.ToInt32(Console.ReadLine());
int combination = Factorial(n) / (Factorial(n - k) * Factorial(k));
Console.WriteLine("C(" + n + ", " + k + ") = " + combination);
Console.ReadKey();
}
}
}
【问题讨论】:
标签: c# class combinations factorial