int main()
{
int n, i, sum;
cout << "Enter a value for n: ";
cin >> n;
sum = 0;
i = 1;
do
{
sum += i * i;
i++;
}while (i <= n);
cout << "The sum of the first " << n
<< " numbers is " << sum << endl;
return 0;
}
每当我运行此代码并使用4作为示例时,输出变为30.当4的阶乘为24时
答案 0 :(得分:4)
sum+=i*i
- &GT;第一个n
方格的总和。
factorial是
prod=prod*i