#include<math.h>
#include<stdio.h>
/*
数组score,一行代表一个学生的四门成绩
输出有不及格的学生的所有成绩
*/
main(){
float score[][4] = {{60,70,80,90},{56,89,67,88},{34,78,90,66}};
float * search(float(*pointer)[4]);
float *p;
int i,j;
for(i=0;i<3;i++){
p = search(score+i);
if(p==*(score+i)){
printf("No.%d scores :",i);
for(j = 0;j<4;j++){
printf("%5.2f\t",*(p+j));
}
printf("\n");
}
}
}
/*
若学生无不及格成绩,则指针pt指向*(pointer+1),否则指向*pointer
*/
float * search(float(*pointer)[4]){
int i;
float *pt;
pt = *(pointer+1);
for(i = 0;i<4;i++){
if(*(*pointer+i)<60){
pt = *pointer;
}
}
return pt;
}
运行结果为:
No.1 scores :56.00 89.00 67.00 88.00
No.2 scores :34.00 78.00 90.00 66.00