艾草837 2022-05-18 17:42 采纳率: 50%
浏览 13
已结题

为什么输出不到想要的结果(C语言)

img


为什么输出不到想要的结果?

img


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<conio.h>
#define M 10

struct student
{
    int num;
    int score;
};

int fun(struct student *s,int low,int high,struct student *b);

int main()
{
    int low,high;
    int i,t;
    struct student s[M];
    struct student b[M];
    printf("输入学生数据\n");
    for(i=0; i<M; i++)
    {
        scanf("%d%d",&s[i].num,&s[i].score);
    }
    printf("输入分数范围\n");
    scanf("%d%d",&low,&high);
    if ( high < low )
    {
        t=high;
        high=low;
        low=t;
     }
    fun(s,low,high,b);
    printf("符合条件的有:\n");
    do
    {
        printf("%d  %d",b[i].num,b[i].score);
        printf("\n");
        i++;
    }while(getchar()!='\0');
    return 0;
}

int fun(struct student *s,int low,int high,struct student *b)
{
    int i,j=0;
    for(i=0; i<M; i++)
    {
        if(s[i].score>low && s[i].score<=high)
        {
            b[j].num=s[i].num;
            b[j].score=s[i].score;
        }
    }
}

  • 写回答

2条回答 默认 最新

  • kinghero123456 2022-05-18 18:08
    关注
    
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<conio.h>
    #define M 10
    
    struct student
    {
        int num;
        int score;
    };
    
    int fun(struct student *s, int low, int high, struct student *b);
    
    int main()
    {
        int low, high;
        int i, t;
        struct student s[M];
        struct student b[M];
        printf("输入学生数据\n");
        for (i = 0; i < M; i++)
        {
            scanf("%d%d", &s[i].num, &s[i].score);
        }
        printf("输入分数范围\n");
        scanf("%d%d", &low, &high);
        if (high < low)
        {
            t = high;
            high = low;
            low = t;
        }
        int count = fun(s, low, high, b);
        printf("符合条件的有:\n");
        i = 0;
        do
        {
            printf("%d  %d", b[i].num, b[i].score);
            printf("\n");
            i++;
            count--;
        } while (count > 0);
        return 0;
    }
    
    int fun(struct student *s, int low, int high, struct student *b)
    {
        int i, j = 0;
        for (i = 0; i < M; i++)
        {
            if (s[i].score > low && s[i].score <= high)
            {
                b[j].num = s[i].num;
                b[j].score = s[i].score;
                j++;
            }
        }
        return j;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月26日
  • 已采纳回答 5月18日
  • 创建了问题 5月18日

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上