一個學習小組有n(n≤50)學生,每個學生有學號和考試成績2個資訊。撰寫程式實作以下功能:
(1)按學號順序輸入n個學生的學號和成績放入陣列a[50][2]中,并輸出陣列a。
(2)指定一個學號,若該學號在陣列a中,則輸出顯示對應的成績;否則輸出“無此學生!”。
uj5u.com熱心網友回復:
供參考,你抄一遍,加深印象:#include <stdio.h>
#define M 50
#define N 2
int main(int argc, char* argv[])
{
int stu[M][N];
for(int i=0 ;i<M;i++){
printf("請輸入第%d個學生學號和成績:",i+1);
for(int j=0;j<N;j++){
scanf("%d",&stu[i][j]);
}
}
for(int i=0 ;i<M;i++){
printf("第%d個學生學號和成績:",i+1);
for(int j=0;j<N;j++){
printf("%5d%c",stu[i][j],((j==1)? '\n':' '));
}
}
int i,temp;
printf("請輸入要查詢的學號:");
scanf("%d",&temp);
for(i=0;i<M;i++){
if(*stu[i] == temp) break;
continue;
}
if(i==M) printf("無此學生!\n");
else
printf("學號:%d 成績:%d\n",stu[i][0],stu[i][1]);
system("pause");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/234060.html
標籤:C語言
上一篇:C語言求組,大佬救救大一孩子
下一篇:零起點演算法104:第幾天?
