|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是目标函数
#include <stdio.h>
int main()
{
double score[][4] = {{80.0,79.5,90.0,70.5},{90.5,60.0,66.5,79.5},{70.5,60.0,90.0,79.5}};
double *search(double(*pointer)[4],int n);
double *p;
int i,m;
printf("please enter the number of student:");
scanf("%d",&m);
printf("The scores of No.%d are:\n",m);
p = search(score,m);
for(i=0;i<4;i++)
{
printf("%5.2f\t",*(p+i));
printf("\n");
}
}
double *search(double (*pointer)[4],int n)
{
double *pt;
pt = *(pointer+n);
return pt;
}
这是我自己打的函数
#include <stdio.h>
double *search(double *(a)[4],int n)
{
double *pt;
pt = *(a+n);
return pt;
}
int main()
{
int b;
double *p,score[3][4] = {{80.5,70,90,65.5},{55.5,60,96,70.5},{90.5,91,99,85}};
scanf("%d",&b);
printf("the NO.%d student's score is \n");
p = search(score,b);
for(;p<p+4;p++)
{
printf("%lf\n",*p);
}
}
不知道为啥我打的不能编译,大概就是输入数字从而得出几号同学的成绩,麻烦大神指导一下,多谢
#include <stdio.h>
double *search(double (* a)[4],int n)
{
double *pt;
pt = *(a+n);
return pt;
}
int main()
{
int b;
double *q;
double *p,score[3][4] = {{80.5,70,90,65.5},{55.5,60,96,70.5},{90.5,91,99,85}};
scanf("%d",&b);
printf("the NO.%d student's score is \n");
p = search(score,b);
/*
1、用别的变量作循环计数
比如
for(b=0 ; b< 4 ; b++)
{
printf("%lf\n",*p++);
}
*/
//2、定义一个指针变量,先计算出循环结束的地址
//比如 doubel * q = p + 4;
//for(;p<q; p++)
q = p + 4;
for(; p<q ; p++)
{
printf("%lf\n",*p);
}
return 0;
}
|
|