- #include<iostream>
- #include<cstdlib>
- #include<string>
- using namespace std;
- int main(){
- //<法1一維陣列>
- string name[]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
- int chinese[] = {90,70,80,70,80};
- int english[] = {85,75,95,95,85};
- int math[] = {85,80,80,75,95};
- cout<<"座號\t姓名\t\t國文\t英文\t數學"<<endl;
- cout<<"============================================"<<endl;
- for(int i=0;i<5;i++)
- {cout<<i+1<<"\t";
- cout<<name[i]<<"\t"<<"\t"<<chinese[i]<<"\t"<<english[i]<<"\t"<<math[i]<<"\t";
- cout<<endl;
- }
- cout<<endl;
- //<法2二維陣列>
- int score[5][3] = {
- {90,85,85},
- {70,75,80},
- {80,95,80},
- {70,95,75},
- {80,85,95}
- };
- cout<<"座號\t姓名\t\t國文\t英文\t數學"<<endl;
- cout<<"============================================"<<endl;
- for(int i=0;i<5;i++){
- cout<<i+1<<"\t"<<name[i]<<"\t\t";
- for(int j=0;j<3;j++){
- cout<<score[i][j]<<"\t";
- }
- cout<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |