#include "stdio.h" #define M 2 /*设一共有5个学生*/ #define N 3 /*设一个学生有六门课*/ struct student { float score[N]; int num; /*学生学号*/ };
void main() { int i,j,k; float sum=0.0; struct student a[M]; for(i=0;i<M;i++) { printf("please input the number of %d student:\n",i); scanf("%d",&a[i].num); printf("please input the i student score:\n",i); for(j=0;j<N;j++) scanf("%f",&a[i].score[j]); printf("\n"); } for(i=0;i<M;i++) { for(j=0;j<N;j++) if(a[i].score[j]<60) { printf("the student's number is:%d\n",a[i].num); printf("his score is:"); for(k=0;k<N;k++) { printf("%f",a[i].score[k]); sum+=a[i].score[k]; } printf("\nthe average is :%f\n",sum/N); break; } sum=0; } } 当有一门不及格,输出成绩后应该跳出。