学不会c语言不改名. 2021-12-04 17:52 采纳率: 100%
浏览 94
已结题

c语言程序中我想输入一个学号,但是后面输出的学号是乱码

学号那一项该怎么改才正确。

#include <stdio.h>
#define N 30
int ave(int a);
int i, max;
float a, b, c, d, e, f;
int score[N];
char name[N][10];
int number[N][1];

int main () {
    int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, counter5 = 0, counter6 = 0;
    for (i = 0; i < N; i++) {
        printf ("名字:\t");
        scanf ("%s", &name[i]);
        printf("成绩:\t");
        scanf("%d", &score[i]);
        printf("学号:\t");
        scanf("%d", &number[i]);
        if (score[i] < 0)
            break;
        else if (score[i] >= 90)
            counter1++;
        else if (score[i] >= 80)
            counter2++;
        else if (score[i] >= 70)
            counter3++;
        else if (score[i] >= 60)
            counter4++;
        else
            counter5++;
    }
    int p, j;
    f = ave(a);
    for (p = 0; p < N; p++) {
        if (score[p] > f)
            counter6++;
    }
    max = score[0];
    for (j = 0; j < N; j++) {
        if (max < score[j])
            max = score[j];
    }
    a = (counter1 * 100.0 / N);
    b = (counter2 * 100.0 / N);
    c = (counter3 * 100.0 / N);
    d = (counter4 * 100.0 / N);
    e = (counter5 * 100.0 / N);
    printf("最高分是:%d分,其学号为:%d\n", max, number[i]);
    printf("不及格有:%d人,所占百分比为:%.2f%%\n", counter5, e);
    printf("分数>=90占百分比为:%.2f%%\n", a);
    printf("90>分数>=80占百分比为:%.2f%%\n", b);
    printf("80>分数>=70占百分比为:%.2f%%\n", c);
    printf("70>分数>=60占百分比为:%.2f%%\n", d);
    printf("在平均分数之上的有:%d人\n", counter6);
    return 0;
}

int ave(int a) {
    int total = 0, i, b;
    for (i = 0; i < N; i++) {
        total += score[i];
    }
    b = total / N;
    return b;
}

  • 写回答

2条回答 默认 最新

  • qzjhjxj 2021-12-04 19:48
    关注

    修改处见注释,供参考:

    #include <stdio.h>
    #define N 30
    int ave(int a);
    int i, max, max_i;  //修改
    float a, b, c, d, e, f;
    int  score[N];
    char name[N][10];
    int  number[N];   // number[N][1];  修改
    int main () {
        int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, counter5 = 0, counter6 = 0;
        for (i = 0; i < N; i++) {
            printf ("名字:\t");
            scanf ("%s", &name[i]);
            printf("成绩:\t");
            scanf("%d", &score[i]);
            printf("学号:\t");
            scanf("%d", &number[i]);
            if (score[i] < 0)
                break;
            else if (score[i] >= 90)
                counter1++;
            else if (score[i] >= 80)
                counter2++;
            else if (score[i] >= 70)
                counter3++;
            else if (score[i] >= 60)
                counter4++;
            else
                counter5++;
        }
        int p, j;
        f = ave(a);
        for (p = 0; p < N; p++) {
            if (score[p] > f)
                counter6++;
        }
        max = score[0];max_i=0;  //修改
        for (j = 0; j < N; j++) {
            if (max < score[j])     
            {
                max  = score[j];
                max_i= j;           //修改
            }
        }
        a = (counter1 * 100.0 / N);
        b = (counter2 * 100.0 / N);
        c = (counter3 * 100.0 / N);
        d = (counter4 * 100.0 / N);
        e = (counter5 * 100.0 / N);
        printf("最高分是:%d分,其学号为:%d\n", max, number[max_i]); //修改
        printf("不及格有:%d人,所占百分比为:%.2f%%\n", counter5, e);
        printf("分数>=90占百分比为:%.2f%%\n", a);
        printf("90>分数>=80占百分比为:%.2f%%\n", b);
        printf("80>分数>=70占百分比为:%.2f%%\n", c);
        printf("70>分数>=60占百分比为:%.2f%%\n", d);
        printf("在平均分数之上的有:%d人\n", counter6);
        return 0;
    }
    int ave(int a) {
        int total = 0, i, b;
        for (i = 0; i < N; i++) {
            total += score[i];
        }
        b = total / N;
        return b;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月12日
  • 已采纳回答 12月4日
  • 修改了问题 12月4日
  • 创建了问题 12月4日

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?