C语言编程

2024-11-24 13:28:02
推荐回答(4个)
回答1:

#include 
#include 
typedef struct
{
    long number;
    char name[10];
    float score[3];
    float average;
    int rank;
}DAT;
#define N (5)
void func(DAT *d,int n);
int main()
{
    DAT data[N];
    int i;
    for(i=0;i    {
        scanf("%ld %s %f %f %f",&data[i].number,data[i].name,&data[i].score[0],&data[i].score[1],&data[i].score[2]);
    }
    func(data,N);
    for(i=0;i    {
        printf("%-9ld%-10s%-5.1f%-5.1f%-8.1f%-10.1f%-d\n",data[i].number,data[i].name,data[i].score[0],data[i].score[1],data[i].score[2],data[i].average,data[i].rank);
    }
    return 0;
}
int cmp_score(void *a,void *b)
{
    return ((DAT*)b)->average-((DAT*)a)->average;
}
int cmp_number(void *a,void *b)
{
    return ((DAT*)a)->number-((DAT*)b)->number;
}
void func(DAT *d,int n)
{
    int i;
    for(i=0;i    {
        d[i].average=(d[i].score[0]+d[i].score[1]+d[i].score[2])/3.0;
    }
    qsort(d,n,sizeof(DAT),cmp_score);
    for(i=0;i    {
        d[i].rank=i+1;
    }
    qsort(d,n,sizeof(DAT),cmp_number);
}

网页链接

回答2:

#include
int main()
{struct student
{long int a;
char b[10];
float c;
float d;
float e;
int f;
float g;
}man[5];
int i,j,k,l;
for(i=0;i<5;i++)
{scanf("%ld %s %f %f %f",&man[i].a,&man[i].b,&man[i].c,&man[i].d,&man[i].e);
man[i].g=(man[i].c+man[i].d+man[i].e)/3;
}
for(i=0;i<5;i++)
{man[i].f=5;
for(j=0;j<5;j++)
{ if(man[i].g>man[j].g)
man[i].f=man[i].f-1;
}
}
printf("Number: Name: score: Average: rank:\n");
for(i=0;i<5;i++)
printf("%-9ld%-10s%-5.1f%-5.1f%-8.1f%-10.1f%-d\n",man[i].a,man[i].b,man[i].c,man[i].d,man[i].e,man[i].g,man[i].f);
return 0;
}

回答3:

#include
struct student
{
long num;
char name[10];
float score[3];
float ave;
int rank;
};
int main()
{
struct student stu[5];
int i,j,t;
for(i=0;i<5;i++)
{
scanf("%ld %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].ave=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
stu[i].rank=5;
}
for(t=0;t<5;t++)
{
for(i=0;i<5;i++)
{
if(stu[t].ave>stu[i].ave)
stu[t].rank--;
}
}
printf("Number: Name: score: Average: rank:\n");
for(i=0;i<5;i++)
printf("%-9ld%-10s%-5.1f%-5.1f%-8.1f%-10.1f%-d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave,stu[i].rank);
return 0;
}

回答4:

调试没成功,错哪呢