艾草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日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line