1.求第一门课程的平均分
2.找出有两门以上不及格的学生
3.找出平均分在90分以上或全部课程在85分以上的学生
#include<stdio.h>
#include<math.h>
#include<string.h>
#define M 4
#define N 5
void Average(int *arr,int n);
void TwoFail(int *arr);
void OutputFail(int (*p)[N],int i);
void GoodStudents(int *arr);
int main(void){
int arr[M][N]={{34,56,88,99,89},{27,88,99,67,78},{99,90,87,86,89},{78,89,99,56,77}};
Average(arr,0);
TwoFail(arr);
GoodStudents(arr);
}
void Average(int *arr,int n){
int (*p)[N]=arr;
float average=0;
for(int i=0;i<M;i++){
average+=*(*(p+i)+n);
}
printf("the %d class average is %f:",n,average/M);
}
void TwoFail(int *arr){
int (*p)[N]=arr;int flag=0;
for(int i=0;i<M;i++){
flag=0;
for(int j=0;j<N;j++){
if(*(*(p+i)+j)<60)
flag++;
}
if(flag==2){
OutputFail(p+i,i);
continue;
}
}
}
void OutputFail(int (*p)[N],int i){
printf("NO.%d student's fail.\n",i);
float average=0;
printf("scores are:");
for(int j=0;j<N;j++){
printf("%d ",*(*p+j));
average+=*(*p+j);
}
printf("\nAverage is %f\n",average/N);
}
void GoodStudents(int *arr){
int ave90=1,ab85=1;
float average;
int (*p)[N]=arr;
int Good[M];//save good student flag.
for(int i=0;i<M;i++){
Good[i]=0;
}
for(int i=0;i<M;i++){
average=0;ave90=1;ab85=1;
for(int j=0;j<N;j++){
average+=*(*(p+i)+j);
if(*((*p+i)+j)<85){
ab85=0;
}
}
average/=N;
if(average<90)ave90=0;
if(ave90||ab85)Good[i]=1;
}
for(int i=0;i<M;i++)
if(Good[i])
printf("%d is a good student.\n",i);
}
标签:班级,int,void,练习,arr,99,89,include,指针
From: https://www.cnblogs.com/zhongta/p/18202213