案例
代码:
int main()
{
int arr[3][3] = { 100,100,100,90,50,100,60,70,80 };
int sum0 = 0, sum1 = 0, sum2 = 0;
for (int i = 0; i < 3; i++)
{
//如果把sum定义在这为什么不行呢?
for (int j = 0; j < 3; j++)
{
if (i = 0)
{
sum0 += arr[i][j];
}
if (i = 1)
{
sum1 += arr[i][j];
}
if (i = 2)
{
sum2 += arr[i][j];
}
}
}
cout << "张三总成绩为" << sum0 << endl;
//为什么打印出来张三的总成绩为0?
cout << "李四总成绩为" << sum1 << endl;
cout << "王五总成绩为" << sum2 << endl;
请求热心的大佬解答,谢谢!