| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1858 人关注过本帖
标题:在三个学生中输出平均成绩最高的学生信息,请问一下我程序的问题在哪里
只看楼主 加入收藏
yangtanzheng
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2019-7-1
结帖率:66.67%
收藏
已结贴  问题点数:5 回复次数:3 
在三个学生中输出平均成绩最高的学生信息,请问一下我程序的问题在哪里
#include <stdio.h>
struct stu
{
    int num;
    char name[10];
    float score[3];
    float aver;
};
void input (struct stu st1[])
{
    int i;
    printf("please three stu number:\n");
    for(i=0;i<3;i++)
    {
        scanf("%d,%s,%f,%f,%f",&st1[i].num,&st1[i].name,&st1[i].score[0],&st1[i].score[1],&st1[i].score[2]);
        st1[i].aver=(st1[i].score[0]+st1[i].score[1]+st1[i].score[2])/3;
    }
}
void max(struct stu st2[])
{   

    struct stu p;
    int i,j;
    input(st2);
    for(j=0;j<2;j++)
    {
        for(i=0;i<3-j-1;i++)
        {
            if(st2[i].aver<st2[i+1].aver)
            {
                p=st2[i];
                st2[i]=st2[i+1];
                st2[i+1]=p;
            }
        }
    }
    printf("%d,%s,%f,%f,%f",st2[0].num,st2[0].name,st2[0].score[0],st2[0].score[1],st2[0].score[2]);   
}
int main()
{
    struct stu st[3],*p=st;
    max(p);
    return 0;
搜索更多相关主题的帖子: 学生 struct stu int score 
2019-07-19 17:26
GrayJerry
Rank: 5Rank: 5
等 级:贵宾
威 望:14
帖 子:75
专家分:310
注 册:2015-10-20
收藏
得分:3 
max函数要求传入的参数类型为:struct stu st2[],而main方法中调用的max函数,传入的参数是一个struct stu类型的指针变量,类型不匹配
2019-07-20 20:41
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:3 
请问一下我程序的问题在哪里
“问题在哪里?”是你告诉别人。
如果编译失败的话,那应该告诉别人编译器给出的错误信息
如果运行结果不符合你的预期,那应该告诉别人你的输入是什么实际输出是什么你期待的输出是什么

程序代码:
#include <stdio.h>

struct student
{
    int num;
    char name[10];
    float score[3];
    float aver;
};

void input ( struct student st[static 3] )
{
    puts( "please three stu number:" );
    for( size_t i=0; i!=3; ++i )
    {
        scanf( "%d%9s%f%f%f", &st[i].num, st[i].name, &st[i].score[0], &st[i].score[1], &st[i].score[2] );
        st[i].aver = (st[i].score[0]+st[i].score[1]+st[i].score[2])/3;
    }
}

size_t max( const struct student st[static 3] )
{
    size_t index = 0;
    for( size_t i=0; i!=3; ++i )
    {
        if( st[i].aver > st[index].aver )
            index = i;
    }
    return index;
}

int main( void )
{
    struct student st[3];
    input( st );
    size_t index = max( st );
    printf( "%d,%s,%g,%g,%g\n", st[index].num, st[index].name, st[index].score[0], st[index].score[1], st[index].score[2] );
}

输入:
1 张三 10 20 30
2 李四 70 80 90
3 王五 40 50 60
输出:
2,李四,70,80,90


2019-07-22 09:28
yangtanzheng
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2019-7-1
收藏
得分:0 
回复 3楼 rjsp
我明白了 谢谢大佬
2019-07-22 22:03
快速回复:在三个学生中输出平均成绩最高的学生信息,请问一下我程序的问题在哪里 ...
数据加载中...
 
   



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

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