c8-25.c 848 B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. int main()
  3. {float score[ ][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}}; //定义数组,存放成绩
  4. float *search(float (*pointer)[4],int n); // 函数声明
  5. float *p;
  6. int i,k;
  7. printf("enter the number of student:");
  8. scanf("%d",&k); // 输入要找的学生的序号
  9. printf("The scores of No.%d are:\n",k);
  10. p=search(score,k); //调用search函数,返回score[k][0]的地址
  11. for(i=0;i<4;i++)
  12. printf("%5.2f\t",*(p+i)); // 输出score[k][0]到score[k][3]的值
  13. printf("\n");
  14. return 0;
  15. }
  16. float *search(float (*pointer)[4],int n) // 定义函数,形参pointer是指向一维数组的指针变量
  17. {float *pt;
  18. pt=*(pointer+n); // pt的值是&score[k][0]
  19. return(pt);
  20. }