从b站上黑马程序员的C++课里学到的个人成绩统计
1 #include <iostream> 2 #include <string.h> 3 using namespace std; 4 int main() 5 { 6 int scores[3][3] = 7 { 8 {100,100,100}, 9 {90,50,100}, 10 {60,70,80} 11 }; 12 string names[3] = { "张三","李四","王五" }; 13 for (int i = 0; i < 3; i++) //外层循环遍历行 14 { 15 int sum = 0; //统计分数总和变量 16 for (int j = 0; j < 3; j++) //列,内层循环遍历列 17 { 18 sum += scores[i][j]; 19 } 20 cout << names[i] << "的总分为:" << sum << endl; //因为有求和sum,所以names数组放在内层循环遍历列后的地方 21 } 22 return 0; 23 }
运行结果显示:
标签:考试成绩,int,sum,++,二维,数组,scores,100,include From: https://www.cnblogs.com/romantichuaner/p/17571340.html