作者beatall (beat all of you)
站內ask
標題[請問] 請教C語言高手
時間Tue Jun 7 10:02:44 2011
請大大幫我解答此
1以二維矩陣完成成績計算程式(即課堂練習題目)
2宣告一個二維陣列,用以儲存每位同學的各科成績、總分、平均、排名
3各科成績以亂數方式產生(0~100分)
4總分、平均:以程式計算後填入對應欄位
5排名:以總分為基準,將成績資料由高分至低分排序後,填入名次 (注意:學號、成績
資料也要一起搬動,不然會出現只有總分、名次變動的邏輯錯誤)
印出最後(排名後)的成績資料,並請盡量保持格式整齊(各科成績上下對齊)
我已經做到一半了~~
如下
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int student[50][11];
int score[50][3];
int i,j,temp;
srand(time(NULL));
for(i=0;i<50;i++)
{
printf("第%d號同學成績:",i);
for(j=0;j<11;j++)
{
student[i][j]=(rand()%60)+40;
printf("%d ",student[i][j]);
}
printf("\n");
}
for(i=0;i<50;i++)
{
score[i][0]=0;
for(j=0;j<11;j++)
score[i][0] += student[i][j];
score[i][1] = score[i][0]/11;
printf("第%d號同學總分:%d\t 平均:%d\n",i,score[i][0],score[i][1]);
}
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.251.177.24
噓 DKer:ass 06/07 10:03
推 david21911:加油 你可以的 06/07 10:03
噓 DeathBook:有500行以上再來問人 06/07 10:09
噓 kfrankk:都一半了 OK的! 06/07 10:15
噓 asdrin04:C別的我很會 06/07 12:30