标题:这是怎么回事,代码有问题吗?
只看楼主
我忘乐
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2017-7-18
结帖率:83.33%
已结贴  问题点数:5 回复次数:1 
这是怎么回事,代码有问题吗?
#include<stdio.h>
#define N 5
struct student
{
    char num[6];
    char name[8];
    int score[4];
} stu[N];
void main()
{
    void print(struct student stu[6]);
    int i, j;
    for (i = 0; i < N; i++)
    {
        printf("\ninput score of student %d:\n", i + 1);
        printf("NO.:");
        scanf("%s", stu[i].num);
        printf("name:");
        scanf("%s", stu[i].name);
        for (j = 0; j < 3; j++)
        {
            printf("score %d:", j + i);
            scanf("%d", &stu[i].score[j]);
        }
        printf("\n");
    }
    print(stu);
}
void print(struct student stu[6])
{
    int i, j;
    printf("\n NO. name score1 score2 score3\n");
    for (i = 0; i < N; i++)
    {
        printf("%5s%10s", stu[i].num, stu[i].name);
        for (j = 0; j < 3; j++)
            printf("%9d", stu[i].score[j]);
        printf("\n");
    }
}















搜索更多相关主题的帖子: stu name score for printf 
2017-10-17 15:30
pydlq
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:129
专家分:488
注 册:2017-9-5
得分:5 
  printf("score %d:", j + i);
改成 printf("score %d:", j + 1);
再改下输出格式


[此贴子已经被作者于2017-10-18 09:45编辑过]

2017-10-17 19:06



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




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

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