標題:
班上成績處理 (陣列、極端值應用)
[打印本頁]
作者:
stephen
時間:
2010-5-1 11:12
標題:
班上成績處理 (陣列、極端值應用)
本帖最後由 stephen 於 2010-5-1 11:15 編輯
班上成績處理 (陣列、極端值應用)
1. 決定學生人數
2. 利用 rand() 來產生亂數作為學生成績
3. 求出每個學生的平均
4. 求出第一名與最後一名
5. 列印學生成績
[attach]18[/attach]
作者:
b1081081
時間:
2010-5-1 11:15
哈哈我寫好ㄌ
#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;
}
複製代碼
作者:
p17johnny
時間:
2010-5-1 11:19
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
cout<<"感謝各位的協助"<<endl;
srand(time(NULL));
int stu_num;
int max[2];
max[1] = 0;
int min[2];
min[1] = 100;
cout << "**請輸入學生人數**" << endl;
cin >> stu_num;
int jj[stu_num][5];
for(int i = 0; i < stu_num; i++){
jj[i][0] = i + 1;
jj[i][1] = 1 + rand()%100;
jj[i][2] = 1 + rand()%100;
jj[i][3] = 1 + rand()%100;
jj[i][4] = (jj[i][1]+jj[i][2]+jj[i][3]) / 3;
if(jj[i][4] > max[1]){
max[0] = i + 1;
max[1] = jj[i][4];
}else if(jj[i][4] < min[1]){
min[0] = i + 1;
min[1] =jj[i][4];
}
}
cout << "!!!"<<max[0] << "號的平均值最大!!!1,~平均值為" << max[1] <<"~"<< endl;
cout <<"!!!"<< min[0] << "號的平均值最小,平均值為" << min[1] <<"~"<< endl;
system("pause");
return 0;
}
複製代碼
作者:
yachen392
時間:
2010-5-1 11:21
#include<iostream>
#include <cstdlib>
using namespace std;
int main(){
int stu_n=50;//人數
int data[stu_n][5];//學生數量成績
int min[2];
min[0]=100;
int max[2];
max[0]=0;
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];
}
if(data[i][4]<min[1]){
min[0]=i+1;
min[1]=data[i][4];
}
cout << data[i][0] << " " ;
cout << data[i][1] << " " ;
cout << data[i][2] << " " ;
cout << data[i][3] << " " << endl ;
}
cout << "第一名是" << max[0] << "號 平均是" << max[1] << endl;
cout << "最後一名是" <<min[0] << "號 平均是" << min[1] << endl;
system("pause");
return 0;
}
複製代碼
作者:
chuangjoy
時間:
2010-5-1 11:26
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2