array.cpp

来自「C++ sample code, for the book: C++ blac」· C++ 代码 · 共 20 行

CPP
20
字号
#include <iostream>
using namespace std;

int main()
{
    int test_index, student_index, scores[3][5] = {
        { 92 , 73 , 57 , 98 , 89 },    
        { 88 , 76 , 23 , 95 , 72 },    
        { 94 , 82 , 63 , 99 , 94 }
    };
    float sum;

    for (test_index = 0; test_index < 3; test_index++){   
        for (student_index = 0, sum = 0; student_index < 5; student_index++) 
            sum = sum + scores[test_index][student_index];
        cout << "Average for test" << test_index + 1 << " is " << sum / 5 << endl;
    }

    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?