哈哈我寫好ㄌ- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main(void){
-
- srand(time(NULL));
- int stu_num;
- int max[2];
- max[1] = 0;
- int min[2];
- min[1] = 100;
- cout << "輸入學生人數" << endl;
- cin >> stu_num;
- int title[stu_num][5];
-
- for(int i = 0; i < stu_num; i++){
- title[i][0] = i + 1;
- title[i][1] = 1 + rand()%100;
- title[i][2] = 1 + rand()%100;
- title[i][3] = 1 + rand()%100;
- title[i][4] = (title[i][1]+title[i][2]+title[i][3]) / 3;
- if(title[i][4] > max[1]){
- max[0] = i + 1;
- max[1] = title[i][4];
- }else if(title[i][4] < min[1]){
- min[0] = i + 1;
- min[1] = title[i][4];
- }
- }
-
- cout << max[0] << "號的平均值最大,平均值為" << max[1] << endl;
- cout << min[0] << "號的平均值最小,平均值為" << min[1] << endl;
-
- system("pause");
- return 0;
- }
複製代碼 |