需求
代码
#include <stdio.h>
#define N_STUDENT 5 //5个学生
#define N_SCORE 2 //2门课
struct STUDENT
{
int s_no; //学号
char s_name[20]; //姓名
float score[N_SCORE]; //2门课成绩
float ave_score; //平均成绩
}STU[N_STUDENT];
void input(struct STUDENT* p);
void print(struct STUDENT* p);
int main()
{
struct STUDENT* stu = STU;
input(stu);
print(stu);
return 0;
}
void input(struct STUDENT* p)
{
int i;
printf("Please enter the information of each student:");
printf("\nstudent s_no/s_name/c_score/m_score 2:\n");
for ( i= 0; i < N_STUDENT; i++)
{
scanf("%d %s %f %f", &p[i].s_no,p[i].s_name,&p[i].score[0], &p[i].score[1]);
(p + i)->ave_score = ((p + i)->score[0] + (p + i)->score[1])/2.0;
}
}
void print(struct STUDENT* p)
{
int i;
printf("\nall ave_score:\n");
for ( i= 0; i < N_STUDENT; i++)
{
printf("\nstudent s_no:%d\ns_name:%s\nave_score:%3.1f\n",
(p + i)->s_no, (p + i)->s_name,(p + i)->ave_score);
}
printf("\nscore >70:\n");
for ( i= 0; i < N_STUDENT; i++)
{
if((p + i)->ave_score>=70)
{
printf("\nstudent s_no:%d\ns_name:%s\ngrade of courses:%3.1f %3.1f\nave_score:%3.1f\n",
(p + i)->s_no, (p + i)->s_name, (p + i)->score[0], (p + i)->score[1],(p + i)->ave_score);
}
}
}
输入文本
194110111 lell 77 99
194110110 zeng 66 55
194110109 yan 99 88
194110108 li 33 44
194110107 yu 56 98