指针课后作业(找出不及格打印),有错,求助
请教如何改错,double (*pointer)=score[]; p=pointer; 如何改,谢谢#include<stdio.h>
void main()
{
double score[]={{60.0, 70.0, 80.5, 90.5}, {56.0, 89.0, 67.0, 88.0}, {34.2, 78.5, 90.3, 67.5}, {45.5, 66.6, 77.7, 88.8}};
double (*pointer)=score[];
double *p, *pt;
int i, j;
p=pointer;
printf("students <60: ");
for(i=0; i<3; i++)
{
pt=p+i;
for(j=0; j<3; j++)
{
while( *(pt+j)<60 )
{
printf("No. %d student, subject %d is %5.2f\n", i, j, *(pt+j));
}
}
}
}
第五行数组前面要加上&取址 #include<stdio.h>
void main()
{
double score[]={{60.0, 70.0, 80.5, 90.5}, {56.0, 89.0, 67.0, 88.0}, {34.2, 78.5, 90.3, 67.5}, {45.5, 66.6, 77.7, 88.8}};
double* p=score;
int len=sizeof(score)/sizeof(score);
for(int i=0;i<len;i++)
{
if(*(p+i)<60)
{
printf("No. %d student, subject %d is %5.2f\n",i/4+1,i%4+1,*(p+i));
}
}
}
修改完,谢谢!
#include<stdio.h>
void main()
{
double score[]={60.0, 70.0, 80.5, 90.5, 56.0, 89.0, 67.0, 88.0, 34.2, 78.5, 90.3, 67.5, 45.5, 66.6, 77.7, 88.8, 59.0};
double *p=score;
int lengh=sizeof(score)/sizeof(score);
int i;
for(i=0; i<lengh; i++)
{
if(*(p+i)<60)
{
printf("No. %d student, subject %d is %5.2f\n",i/4+1,i%4+1,*(p+i));
}
}
}
页:
[1]