Win-TC编程 高手指教
解决时间 2021-07-17 02:36
- 提问者网友:藍了天白赴美
- 2021-07-16 11:48
已知5个学生的4门课的成绩,要求求出每个学生的平均成绩,然后对平均成绩从高到低将各学生成绩排序记录。
#include "stdio.h"
#include "conio.h"
#define N 5
struct student
{
char num[6];
char name[8];
int score[4];
}stu[N];
input(stu)
struct student stu[];
{
int i,j;
for(i=0;i<N;i++)
{
printf("\n please input %d of %d\n",i+1,N);
printf("num: ");
scanf("%s",stu[i].num);
printf("name: ");
scanf("%s",stu[i].name);
for(j=0;j<4;j++)
{
printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
}
printf("\n");
}
}
print(stu)
struct student stu[];
{
int i,j;
printf("\nNo. Name Sco1 Sco2 Sco3\n");
for(i=0;i<N;i++)
{
printf("%-6s%-10s",stu[i].num,stu[i].name);
for(j=0;j<4;j++)
printf("%-8d",stu[i].score[j]);
printf("\n");
}
}
main()
{
input();
print();
getch();
}
我写到这里 求平均 和 排序 不会做了
最佳答案
- 五星知识达人网友:山河有幸埋战骨
- 2021-07-16 12:40
#include <stdio.h>
#include <conio.h>
#define N 5
struct student
{
char num[10];
char name[10];
float score[4];
float average;
}stu[N],temp;
static void forcefloat(float *p)
{
float f = *p;
forcefloat(&f);
}
int main ()
{
int i,j;
float total;
for (i=0;i<N ;i++){
printf("input the student num:\n");
scanf("%s",stu[i].num);
printf ("input the student name:\n");
scanf("%s",stu[i].name);
for (j=0,total=0;j<4;j++) {
printf ("input the %dth score:\n",j);
scanf("%f",&(stu[i].score[j]));
total+= stu[i].score[j];
}
stu[i].average=total/j;
}
for (i=N-1;i>0;i--)
for(j=0;j<i;j++) {
if (stu[j].average<stu[j+1].average) {
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
for (i=0;i<N ;i++){
printf("student num:%s\n",stu[i].num);
printf ("student name:%s\n",stu[i].name);
for (j=0;j<4;j++) {
printf ("the %dth score:%f\n",j,stu[i].score[j]);
}
}
getch();
}
win-tc运行通过
全部回答
- 1楼网友:梦中风几里
- 2021-07-16 13:45
#include "stdio.h"
#include "conio.h"
#define N 5
struct student
{
char num[6];
char name[8];
float score;//分数就不用数组了
}stu[N];
input(stu)
//struct student stu[];
{
int i,j;
for(i=0;i<N;i++)
{
printf("\n please input %d of %d\n",i+1,N);
printf("num: ");
scanf("%s",stu[i].num);
printf("name: ");
scanf("%s",stu[i].name);
//r(j=0;j<4;j++)
//{
printf("score %d.",j+1);
scanf("%d",&stu[i].score);
//}
printf("\n");
}
}
print(stu)
//struct student stu[];
{
int i,j;
printf("\nNo. Name Sco1 Sco2 Sco3\n");
for(i=0;i<N;i++)
{
printf("%-6s%-10s",stu[i].num,stu[i].name);
for(j=0;j<4;j++)
printf("%-8d",stu[i].score[j]);
printf("\n");
}
}
main()
{
input();
print();
getch();
}
逻辑不怎么对啊!等下我个重写一个
我要举报
大家都在看
推荐资讯