成功地处理dos但c#中的问题? [英] succcesfully work on dos but problems in c# ?
本文介绍了成功地处理dos但c#中的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从c#design转换到控制台时出现问题;
在dos模式下
它成功计算但在设计模式下它只计算到26 !, i在26中获得低于零( - )的结果! ;
继承我的代码?问题是什么?
i got problems to convert it to console from c# design;
in dos mode its succesful to compute but in design mode its only calculating till 26!, i got a below zero (-) result in 26! ;
heres my code ? wheres the problem?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace can
{
class Program
{
static void Main(string[] args)
{
int k;
Console.WriteLine("Enter a number whose factorial needs to be calculated: ");
k = Convert.ToInt32(Console.ReadLine());
int[] numArr = new int[10000];
int total,rem=0,count,i;
for(i=0;i<9999;i++)
numArr[i]=0;
numArr[9999]=1;
for(count = 2 ; count <= k ; count++)
{
while(i>0)
{
total = numArr[i] * count + rem;
rem=0;
if(total>9)
{
numArr[i]=total%10;
rem=total/10;
}
else
{
numArr[i]=total;
}
i--;
}
rem=0;
total=0;
i=9999;
}
Console.WriteLine("The factorial of " + k + " is ");
for(i=0;i<10000;i++)
{
if(numArr[i]!=0 || count==1)
{
Console.Write(numArr[i]);
count=1;
}
}
Console.ReadLine();
}
}
}
推荐答案
我建议你看一下你如何计算阶乘。
快速谷歌搜索后,这似乎是一种明智的做法。
http://guyellisrocks.com/algorithms/factorial-function-in-c/ [ ^ ]
对于您正在尝试的内容,这是一种更清晰的方法,并且不再需要您正在应用的mod函数。
I would advise looking at how you are calculating the factorial.
After a quick Google search this seems like a sensible approach.
http://guyellisrocks.com/algorithms/factorial-function-in-c/[^]
It is a much cleaner approach to what you are attempting and removes the need for the mod function you are applying.
这篇关于成功地处理dos但c#中的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文