题目
2. 3. 4. 计算1!+2!+3!+…+10! 出现了经典错误
#include<stdio.h>
int main()
{
int a = 1;
int sum = 0;
for (int n = 1; n <= 10; n++)
{
for (int i = 1; i <= n; i++)
{
a *= i;
}
sum += a;
}
printf("%d", sum);
return 0;
}
找找错误在哪吧
答案
1.选C,注意b 2.选D,这就很迷惑了 3.打印5死循环,注意不是1234555555555555555555555死循环 4.
#include<stdio.h>
int main()
{
int a = 1;
int sum = 0;
int n = 0;
scanf_s("%d", &n);
for (int i = 1; i <= n; i++)
{
a *= i;
sum += a;
}
printf("%d", sum);
return 0;
}
这是正确答案1
#include<stdio.h>
int main()
{
int sum = 0;
for (int n = 1; n <= 10; n++)
{
int a = 1;
for (int i = 1; i <= n; i++)
{
a *= i;
}
sum += a;
}
printf("%d", sum);
return 0;
}
|