求助啊,大佬們結構體完全不懂啊,馬上要交作業了,很慌啊
。江湖救急!!!!【問題描述】有10個學生,每個學生的資料包括學號、姓名、3門課程的成績,從鍵盤輸入10個學生資料,要求輸出3門課程10個學生的平均成績,以及最高分的學生的資料(包括學號、姓名、3門課程成績,平均分數) ,請使用結構體設計學生的資料。
【輸入形式】
學號 姓名 成績1 成績2 成績3
學號 姓名 成績1 成績2 成績3
...
學號 姓名 成績1 成績2 成績3
學號 1 ~ 10, 姓名少于10個漢字,每個字之間不能留空格, 成績保留小數點后1位數。
【輸出形式】
1 平均成績1
學號 姓名 成績1 成績2 成績3 平均分
2 平均成績2
學號 姓名 成績1 成績2 成績3 平均分
3 平均成績3
學號 姓名 成績1 成績2 成績3 平均分
其中 每一門課程由兩行資訊構成, 第一行是課程資訊,包括課程號和該課程的平均成績,第二行是該門課成績最高的那位學生的資訊,平均分為該學生三門課的成績平均。 輸出的成績和平均分保留小數點后1位數。輸出格式:printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",
【樣例輸入】
1 達吾然·木扎帕爾 90 85 89
2 鄧艷麗 85 90 87
3 馮文豪 78 89 96
4 付豪 83 83 90
5 高帥 69 82 70
6 谷祥洪 92 83 70
7 郭廷昊 80 79 90
8 黃玉瑤 70 80 93
9 金昌璞 90 60 60
10 羅蒙健 98 69 85
【樣例輸出】
0 83.5
10 羅蒙健 98.0 69.0 85.0 84.0
1 80.0
2 鄧艷麗 85.0 90.0 87.0 87.3
2 83.0
3 馮文豪 78.0 89.0 96.0 87.7
uj5u.com熱心網友回復:
不要什么都不寫,什么都不做,就讓別人幫你寫好,除錯正確了。別人不一定這么閑,如果真想要,付費給別人吧~天上掉餡餅的事情想想就好,沒那么多好事~
現在想起來要交作業了,早干嘛去了?
uj5u.com熱心網友回復:
#include <stdio.h>#define N 10
struct Student
{
int num;
char name[10];
float score[3];
float aver;
};
int main()
{
int i;
struct Student stu[N];
struct Student *p=stu;
void average(struct Student stu[N]);
for(i=0;i<N;i++)
{
scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i]. score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3;
}
average(p);
return 0;
}
void average(struct Student stu[N])
{
int i,j,k,max[3];
float sum,
aver[3];
for(i=0;i<3;i++)
{
sum=0;
for(j=0;j<N;j++)
{
sum+=stu[j].score[i];
max[i]=j;
for(k=1;k<N;k++)
{
if(stu[j].score[i]<stu[k].score[i])
{
max[i]=k;
}
}
}
aver[i]=sum/3;
}
for(i=0;i<3;i++)
{
printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",i,aver[i],max[i],stu[max[i]].name,
stu[max[i]].score[0],stu[max[i]].score[1],stu[max[i]].
score[2],stu[max[i]].aver);
}
}
uj5u.com熱心網友回復:
那個那里錯了,能不能幫忙看一下,結果不太對uj5u.com熱心網友回復:
#include <stdio.h>
#define N 3
struct Student
{
int num;
char name[10];
float score[3];
float aver;
};
int main()
{
int i;
struct Student stu[N];
struct Student *p=stu;
void average(struct Student stu[N]);
for(i=0;i<N;i++)
{
scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i]. score[0],&stu[i].score[1],&stu[i].score[2]);
//stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3;
stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3.0;
}
average(p);
return 0;
}
void average(struct Student stu[N])
{
int i,j,k,max[3];
float sum,
aver[3];
for(i=0;i<3;i++) {
sum = 0;
max[i] = 0;
for(j=0;j<N;j++) {
sum += stu[j].score[i];
if (stu[j].score[i] > stu[max[i]].score[i])
max[i] = j;
}
aver[i]=sum / 3.0;
}
/*
for(i=0;i<3;i++)
{
sum=0;
for(j=0;j<N;j++)
{
sum+=stu[j].score[i];
for(k=1;k<N;k++)
{
if(stu[j].score[i]<stu[k].score[i])
{
max[i]=k;
}
}
}
aver[i]=sum/3;
}
*/
for(i=0;i<3;i++)
{
printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",i,aver[i],max[i],stu[max[i]].name,
stu[max[i]].score[0],stu[max[i]].score[1],stu[max[i]].
score[2],stu[max[i]].aver);
}
}
供參考~
對比代碼找一下自己的問題~
uj5u.com熱心網友回復:
萬分感謝


轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/44296.html
標籤:C語言
上一篇:c++,c2059:syntax error '<'怎么解決,編譯可以,運行出錯
下一篇:C++習題
