- /*/////////////////////////////////////////////////////////////////////////////
- 文件名:函数指针
- 时间:2011/9/18
- /////////////////////////////////////////////////////////////////////////////*/
- #include<stdio.h>
- /*/////////////////////////////////////////////////////////////////////////////
- 函数名:FindAddress
- 函数功能:查找学生成绩行地址函数的实现。通过传递的行
- 地址找到要查找学生成绩的地址,并返回行地址
- 入口参数:
- 出口参数:
- /////////////////////////////////////////////////////////////////////////////*/
- int *FindAddress(int (*ptrScore)[4],int n)
- {
- int *ptr;
- ptr=*(ptrScore+n);
- return ptr;
- }
- /*/////////////////////////////////////////////////////////////////////////////
- 函数名:Display
- 函数功能:输出成绩的实现函数,利用传递过来的指针输出
- 每门课的成绩
- 入口参数:
- 出口参数:
- /////////////////////////////////////////////////////////////////////////////*/
- void Display(int n,int *p)
- {
- int col;
- for(col=0;col<n;col++)
- printf("%4d",*(p+col));
- printf("\n");
- }
- /*/////////////////////////////////////////////////////////////////////////////
- 函数名:main
- 函数功能:主函数
- 入口参数:
- 出口参数:
- /////////////////////////////////////////////////////////////////////////////*/
- void main()
- {
- int row,n=4;
- int *p;
- int score[3][4]={{76,87,85,81},{67,61,71,60},{81,89,82,78}};
- printf("请输入学生的编号(1或2或3)。输入0退出程序。\n");
- scanf("%d",&row);
- while(row)
- {
- if( row == 1 || row == 2 || row==3 )
- {
- printf("第%d个学生的成绩4门课的成绩是:\n",row);
- p=FindAddress(score,row-1);//调用指针函数
- Display(n,p);//调用输出成绩函数
- printf("请输入学生的编号(1或2或3),输入0退出程序。\n");
- scanf("%d",&row);
- }
- else
- {
- printf("输入不合法,重新输入(1或2或3)。输入0退出程序");
- scanf("%d",&row);
- }
- }
- }
|