c语言小程序 求教················
- 提问者网友:贪了杯
- 2021-03-21 04:31
- 五星知识达人网友:末日狂欢
- 2021-03-21 05:17
你是不是想要这个结果?
程序帮你看了下,费了老大劲,发现两个小错误。下面注释出了。如果解决了问题请“加分”采纳哦,一分不给不厚道啊。
#include
#include
float ave_stu_score(float (*p)[5])//学生平均分
{
float ave,sum=0;
int i;
for(i=0;i<5;i++)
sum=sum+*(*p+i);
ave=sum/5;
return ave;
}
float ave_sub_score(float *p)//学科平均分
{
float sum=0,ave;
int i;
for(i=0;i<4;i++)
sum=sum+*(p+i);
ave=sum/4;
return ave;
}
void bad(float (*p)[5])//首地址输入
{
int i,j,n;
for(i=0;i<4;i++)
{
n=0;
for(j=0;j<5;j++)
if(*(*(p+i)+j)<60)
n++;
if(n>=2)
{
printf("student who do not pass : student%d
",i+1);printf("his score:");
for(j=0;j<5;j++)
printf("%5.2f,",*(*(p+i)+j));
printf("
his average score is %5.2f
",ave_stu_score(p+i));}
}
}
void good(float (*p)[5])//首地址
{
int i,j,n;
printf("Good students are as follows
");for(i=0;i<4;i++)
{
n=0;
for(j=0;j<5;j++)
if(*(*(p+i)+j)>=85)
n++;
if(n==5 || ave_stu_score(p+i)>=90)
{
printf("student%d
his score is ", i+1);//这里的i+1我填上的for(j=0;j<5;j++)
printf("%5.2f,",*(*(p+i)+j));
}
}
}
void main()
{
float score[4][5];
int i,j;
printf("input students'score:
");for(i=0;i<4;i++)
{
printf("input student%d's score:
",i+1);for(j=0;j<5;j++)
scanf("%f",(*(score+i)+j));//%d错了,应该是%f
}
printf("********************1******************************
");
printf("the first subject A 's average score is %5.2f
",ave_sub_score(*score));
printf("*******************bad students********************************
");bad(score);
printf("*******************good students******************************
");good(score);
system("pause"); //我填的,为了能看到结果
}
- 1楼网友:慢性怪人
- 2021-03-21 06:11