返回信息流RT...
一开始以为int64 或许可以搞定.
然后考虑decimal应该能搞定.
现实是: 都悲剧了..只能计算到27的阶乘..~~
这是一条镜像帖。来源:北邮人论坛 / dot-net / #2136同步于 2010/7/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖
问个很SB的问题.如何.Net 计算100的阶乘
lixunhuan
2010/7/11镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
int 64 可以计算20的 阶乘.
decimal 可以计算到27 ...
ulong =uint64 估计最多也到21 的阶乘..
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Factorial100
{
class Program
{
static void Main(string[] args)
{
while (true)
{
int count = int.Parse(Console.ReadLine().Trim());
Console.WriteLine(FactorialInt(count));
}
}
public static Decimal Factorial(int index)
{
Decimal result = 1;
index = index + 1;
for (int i = 1; i < index; i++)
{
result = result * i;
Console.WriteLine("Current index {0}, result {1}", i, result);
}
return result;
}
public static Int64 FactorialInt(int index)
{
Int64 result = 1;
index = index + 1;
for (int i = 1; i < index; i++)
{
result = result * i;
Console.WriteLine("Current index {0}, result {1}", i, result);
}
return result;
}
}
}
阶乘一般都是用每位单独乘+存储的方式实现的
可以参见如下文章
http://www.cnblogs.com/ReggieCao/archive/0001/01/01/1525176.html
【 在 lixunhuan (李寻欢) 的大作中提到: 】
: RT...
: 一开始以为int64 或许可以搞定.
: 然后考虑decimal应该能搞定.
: ...................
段总威武
【 在 snoopyboy 的大作中提到: 】
: 阶乘一般都是用每位单独乘+存储的方式实现的
: 可以参见如下文章
: http://www.cnblogs.com/ReggieCao/archive/0001/01/01/1525176.html
: ...................
【 在 snoopyboy 的大作中提到: 】
: 阶乘一般都是用每位单独乘+存储的方式实现的
: 可以参见如下文章
: http://www.cnblogs.com/ReggieCao/archive/0001/01/01/1525176.html
: ...................
thanks:) 有空再研究一下..
其实这个是上周的一个面试题目..
貌似自己做错了~~~
这个其实就是人们一般手工计算的思维方式哦~
【 在 lixunhuan (李寻欢) 的大作中提到: 】
: thanks:) 有空再研究一下..
: 其实这个是上周的一个面试题目..
: 貌似自己做错了~~~
: ...................
【 在 snoopyboy 的大作中提到: 】
: 这个其实就是人们一般手工计算的思维方式哦~
: 【 在 lixunhuan (李寻欢) 的大作中提到: 】
: : thanks:) 有空再研究一下..
: ...................
写大牛:) ~ 等明天的笔试结束了 再整理一下算法:)