鱼C论坛

 找回密码
 立即注册
查看: 633|回复: 1

[已解决]求助

[复制链接]
发表于 2020-11-30 13:09:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
输入4个学生的5门成绩,分别用函数实现以下功能:
1:打印每个学生的成绩
2:求每个学生的平均分
3:求每门课的平均分
题目要求我不能调用库函数,只能自己定义函数,我刚学数组,不明白怎么弄这个
最佳答案
2020-11-30 15:42:29
  1. /*输入4个学生的5门成绩,分别用函数实现以下功能:
  2. 1:打印每个学生的成绩
  3. 2:求每个学生的平均分
  4. 3:求每门课的平均分*/
  5. #include <stdio.h>
  6. void print(float scores[][5],int m,int n)//打印每个学生的成绩
  7. {
  8.     int i,j;
  9.     for(i=0;i<m;i++)
  10.     {
  11.         printf("第%d位学生的成绩分别为:",i+1);
  12.         for(j=0;j<n;j++)
  13.             printf("%f,",scores[i][j]);
  14.         printf("\n");
  15.     }
  16. }
  17. void average1(float scores[][5],float *ave1,int m,int n)//求每个学生的平均分
  18. {
  19.     float temp;
  20.     int i,j;
  21.     for(i=0;i<m;i++)
  22.     {
  23.         temp=0;
  24.         for(j=0;j<n;j++)
  25.             temp+=*(*(scores+i)+j);
  26.         *(ave1+i)=temp/n;
  27.     }
  28. }
  29. void average2(float scores[][5],float *ave1,int m,int n)//求每门课的平均分
  30. {
  31.     float temp;
  32.     int i,j;
  33.     for(i=0;i<n;i++)
  34.     {
  35.         temp=0;
  36.         for(j=0;j<m;j++)
  37.             temp+=*(*(scores+j)+i);
  38.         *(ave1+i)=temp/m;
  39.     }
  40. }
  41. int main()
  42. {
  43.     float scores[4][5],ave1[4],ave2[5];
  44.     int i,j;
  45.     for(i=0;i<4;i++)
  46.         for(j=0;j<5;j++)
  47.             scanf("%f",&scores[i][j]);
  48.     print(scores,i,j);
  49.     average1(scores,ave1,i,j);
  50.     average2(scores,ave2,i,j);
  51.     for(i=0;i<4;i++)
  52.         printf("第%d位同学平均成绩为:%.2f\n",i+1,ave1[i]);
  53.     for(j=0;j<5;j++)
  54.         printf("第%d门课程的平均成绩为:%.2f\n",j+1,ave2[j]);
  55.     return 0;
  56. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-11-30 15:42:29 | 显示全部楼层    本楼为最佳答案   
  1. /*输入4个学生的5门成绩,分别用函数实现以下功能:
  2. 1:打印每个学生的成绩
  3. 2:求每个学生的平均分
  4. 3:求每门课的平均分*/
  5. #include <stdio.h>
  6. void print(float scores[][5],int m,int n)//打印每个学生的成绩
  7. {
  8.     int i,j;
  9.     for(i=0;i<m;i++)
  10.     {
  11.         printf("第%d位学生的成绩分别为:",i+1);
  12.         for(j=0;j<n;j++)
  13.             printf("%f,",scores[i][j]);
  14.         printf("\n");
  15.     }
  16. }
  17. void average1(float scores[][5],float *ave1,int m,int n)//求每个学生的平均分
  18. {
  19.     float temp;
  20.     int i,j;
  21.     for(i=0;i<m;i++)
  22.     {
  23.         temp=0;
  24.         for(j=0;j<n;j++)
  25.             temp+=*(*(scores+i)+j);
  26.         *(ave1+i)=temp/n;
  27.     }
  28. }
  29. void average2(float scores[][5],float *ave1,int m,int n)//求每门课的平均分
  30. {
  31.     float temp;
  32.     int i,j;
  33.     for(i=0;i<n;i++)
  34.     {
  35.         temp=0;
  36.         for(j=0;j<m;j++)
  37.             temp+=*(*(scores+j)+i);
  38.         *(ave1+i)=temp/m;
  39.     }
  40. }
  41. int main()
  42. {
  43.     float scores[4][5],ave1[4],ave2[5];
  44.     int i,j;
  45.     for(i=0;i<4;i++)
  46.         for(j=0;j<5;j++)
  47.             scanf("%f",&scores[i][j]);
  48.     print(scores,i,j);
  49.     average1(scores,ave1,i,j);
  50.     average2(scores,ave2,i,j);
  51.     for(i=0;i<4;i++)
  52.         printf("第%d位同学平均成绩为:%.2f\n",i+1,ave1[i]);
  53.     for(j=0;j<5;j++)
  54.         printf("第%d门课程的平均成绩为:%.2f\n",j+1,ave2[j]);
  55.     return 0;
  56. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-12 18:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表