活不明白


私信TA

用户名:hbmb

访问量:15531

签 名:

等  级
排  名 1134
经  验 3074
参赛次数 0
文章发表 38
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>



struct stu{

char num[20];

char name[10];

int score1;

int score2;

int score3;

};


int input(struct stu *p,int N)

{

struct stu *q;

for(q=p;q<p+N;q++)

{

scanf("%s%s%d%d%d",&(q->num),&(q->name),&(q->score1),&(q->score2),&(q->score3));



}

return 0;

}



int average(struct stu *p,int N)

{

int i,tmp1=0,tmp2=0,tmp3=0;

for(i=0;i<N;i++)

{

tmp1+=(p+i)->score1;

}

for(i=0;i<N;i++)

{

tmp2+=(p+i)->score2;

}

for(i=0;i<N;i++)

{

tmp3+=(p+i)->score3;

}

printf("%d %d %d\n",tmp1/N,tmp2/N,tmp3/N);

return 0;

}

int average2(struct stu *p,int N)

{

int i,k=0;

int a[N];

for(i=0;i<N;i++)

{

a[i]=((p+i)->score1+(p+i)->score2+(p+i)->score3)/3;

}

for(i=1;i<=N-1;i++)

{

if(a[0]<a[i])

{

k=i;

a[0]=a[k];

}

}

printf("%s %s %d %d %d\n",(p+k)->num,(p+k)->name,(p+k)->score1,(p+k)->score2,(p+k)->score3);

return 0;

}

int main()

{

int N;

scanf("%d",&N);


struct stu cl[N];

struct stu *p;

p=cl;

input(p,N);

average(p,N);

average2(p,N);



    return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区