- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int main(void){
-
- int stu_n = 50;
- int data[stu_n][6];
- int min[2];
- min[1] = 100;
- int max[2];
- max[1] = 0;
-
- cout << "請輸入學生人數" << endl;
- cin >> stu_n;
-
- for(int i = 0 ; i < stu_n ; i++){
- data[i][0] = i + 1; //座號
- data[i][1] = rand()%100; //成績 1
- data[i][2] = rand()%100; //成績 2
- data[i][3] = rand()%100; //成績 3
- data[i][4] = (data[i][1] + data[i][2] + data[i][3]) / 3; //平均
-
- if(data[i][4] > max[1]){
- max[0] = i+1;
- max[1] = data[i][4];
-
- }else if(data[i][4] < min[1]){
- min[0] = i+1;
- min[1] = data[i][4];
- }
-
- }
-
- for(int i = 0 ; i < stu_n ; i++){
- cout << data[i][0] << " ";
- cout << data[i][1] << " ";
- cout << data[i][2] << " ";
- cout << data[i][3] << " ";
- cout << data[i][4] << " ";
- cout << endl;
- }
-
- cout << "第一名是 " << max[0] << " 號,平均為 " << max[1] << "分" << endl;
- cout << "最後一名是 " << min[0] << " 號,平均為 " << min[1] << "分" << endl;
-
- system("pause");
- return 0;
- }
複製代碼 |