EG:有3个人, 每个人有4门课的成绩.求所有分数的平均分,以及输出第二个人的分数,最后,如果有哪个人的成绩中有不及格的分数,把他的分数输出.
void average(float *p,int n) { float *p_end; float score[3][4],aver,sum=0; p_end=p+n-1; for(;p<=p_end;p++) {sum+=*p;} aver=sum/n; printf("the average is %5.2f",aver); } void search(float (*p)[4],int n) { int i; printf("the score of NO.%d are:\n",n); for(i=0;i<4;i++) printf("%5.2f",*(*(p+n)+i)); }
main() { { void average(float *p,int n); void search(float (*p)[4],int n); float score[3][4]={{56,67,78,89,},{45,65,76,87},{67,90,98,97}}; average(*score,12); search(score,2); } { void search(float (*p)[4],int n); float score[3][4]={{56,67,78,89,},{45,65,76,87},{67,90,98,97}}; search(score,3); { void search(float (*p)[4],int n) int i,j,flag; for(i=0;i<n;i++) {flag=0; for(j=0;j<4;j++) if((*(*p+i)+j)<60) flag=1; if(flag==1) printf("the NO.%d failed,and the score are:\n",i); for(j=0;j<4;j++) printf("%5.2f",*(*(p+i)+j)); } } }
getch(); }