Hamid2547
یک شنبه 13 آذر 1390, 00:09 صبح
به نظر شما مشکل این برنامه چیه؟این برنامه قراره عدد N رو دریافت و !S=1!+2!+3!...N رو حساب کنه،به طور مثال سه رو وارد کردیم باید 9 رو توی مقدار S بریزه ولی خروجی 15 میشه و نمیدونم چرا.
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
int result = 1;
int sumofall = 0;
for (int i = 1; i <= a;i++ )
{
for (int j = 1; j <= i;j++ )
{
result = result * j;
}
sumofall = sumofall + result;
}
Console.WriteLine("The sum of all fatorial is {0}", sumofall);
Console.ReadLine();
}
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
int result = 1;
int sumofall = 0;
for (int i = 1; i <= a;i++ )
{
for (int j = 1; j <= i;j++ )
{
result = result * j;
}
sumofall = sumofall + result;
}
Console.WriteLine("The sum of all fatorial is {0}", sumofall);
Console.ReadLine();
}