标题:求15个学生,10门功课的平均分的程序
只看楼主
zhang22hong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-12-13
 问题点数:0 回复次数:4 
求15个学生,10门功课的平均分的程序
编写求15个学生,10门功课的平均分,我有急用,麻烦大家帮个忙
搜索更多相关主题的帖子: 平均分 功课 学生 
2008-12-13 13:03
Tchong
Rank: 1
等 级:新手上路
帖 子:117
专家分:0
注 册:2008-10-17
得分:0 
你想要的是那一种算法呢?
我帮你列的是指针的算法吧;
应该是使用结构体的吧;
struct student
{
    float score;}stu[15]={{45},{55},{87},{94},{78},{58},{99},{77},{89},{67},{34},{22},{60},{40},{75}
};
#include<stdio.h>
main()
{
void ave(struct student stu[],int n);
ave(stu,15);
}
void ave(struct student stu[],int n)
{
int c=0;
int i;
float ave,s=0;
  for(i=0;i<n;i++)
{
   s+=stu[i].score;
}
ave=s/15;
printf("average=%f\n",ave);
}



还有另外的算法的:
#include<stdio.h>
void main()
{
 int a[15];
    int i;
int j;
int sum=0;
float ave;
printf("Input fifteen students' scores:");
  for(i=0;i<15;i++)
{  
scanf("%d",&a[i]);
}

   for(j=0;j<15;j++){
    sum+=a[j];
    }
 ave=sum/15;
  printf("The average is %f\n",ave);
}


但是第二种是一种很菜的做法啊,小弟不才,虽然有很多想法,但是很忙,希望上面的算法能帮到你
2008-12-13 14:40
Tchong
Rank: 1
等 级:新手上路
帖 子:117
专家分:0
注 册:2008-10-17
得分:0 
struct student
{
    float score;}stu[15][10]={{45,44,67,68,70,45,88,99,55,78},{55,44,67,68,70,45,88,99,55,78},{87,44,67,68,70,45,88,99,55,78},{94,44,67,68,70,45,88,99,55,78},{78,44,67,68,70,45,88,99,55,78},{58,44,67,68,70,45,88,99,55,78},{99,44,67,68,70,45,88,99,55,78},{77,44,67,68,70,45,88,99,55,78},{89,44,67,68,70,45,88,99,55,78},{67,44,67,68,70,45,88,99,55,78},{34,44,67,68,70,45,88,99,55,78},{22,44,67,68,70,45,88,99,55,78},{60,44,67,68,70,45,88,99,55,78},{40,44,67,68,70,45,88,99,55,78},{75,44,67,68,70,45,88,99,55,78}
};
#include<stdio.h>
main()
{
void ave(struct student stu[],int n);
ave(stu,15);
}
void ave(struct student stu[],int n)
{
int c=0;
int i,j;
float ave,s=0;
  for(i=0;i<n;i++)
{ for(j=0;j<10;j++){
   s+=stu[i][j].score;
}
ave=s/15;
printf("average=%f\n",ave);
}
2008-12-13 14:53
Tchong
Rank: 1
等 级:新手上路
帖 子:117
专家分:0
注 册:2008-10-17
得分:0 
如果是是求每一科的平均分,上面的程序改一点就可以,不用我再说了吧
struct student
{
    float score;}stu[15][10]={{45,44,67,68,70,45,88,99,55,78},{55,44,67,68,70,45,88,99,55,78},{87,44,67,68,70,45,88,99,55,78},{94,44,67,68,70,45,88,99,55,78},{78,44,67,68,70,45,88,99,55,78},{58,44,67,68,70,45,88,99,55,78},{99,44,67,68,70,45,88,99,55,78},{77,44,67,68,70,45,88,99,55,78},{89,44,67,68,70,45,88,99,55,78},{67,44,67,68,70,45,88,99,55,78},{34,44,67,68,70,45,88,99,55,78},{22,44,67,68,70,45,88,99,55,78},{60,44,67,68,70,45,88,99,55,78},{40,44,67,68,70,45,88,99,55,78},{75,44,67,68,70,45,88,99,55,78}
};
#include<stdio.h>
main()
{
void ave(struct student stu[],int n);
ave(stu,15);
}
void ave(struct student stu[][10],int n)
{
int c=0;
int i,j;
float ave,s=0;
  for(i=0;i<n;i++)
{ for(j=0;j<10;j++){
   s+=stu[i][j].score;
}
ave=s/15;
printf("average=%f\n",ave);
}
2008-12-13 15:01
xlh5225
Rank: 2
等 级:论坛游民
威 望:2
帖 子:188
专家分:25
注 册:2007-8-14
得分:0 
一群无聊的了,做这种作业
2008-12-13 15:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-249124-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.197478 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved