标题:在2019VS上运行不出来,咋回事?
只看楼主
CCCCW
Rank: 2
等 级:论坛游民
帖 子:8
专家分:27
注 册:2022-2-26
结帖率:66.67%
已结贴  问题点数:20 回复次数:2 
在2019VS上运行不出来,咋回事?
#include<stdio.h>
struct student {     //学生信息结构定义
    int num;       //学号
    char name[10];   //姓名
    int computer, english, math;  //三门课成绩
    double average;     //个人平均分
};
int main(void)
{
    int i, n;
    struct student s1, max;    //定义结构变量
    printf("Input n:");
    scanf_s("%d", &n);
    printf("Input the student's number,name and course scors\n");
    for (i = 1; i <= n; i++)
    {
        printf("No.% d:", i);
        scanf_s("%d%s%d%d%d", &s1.num, s1.name, &s1.math, &s1.english, &);//此处提示波浪线
        s1.average = (s1.math + s1.english + ) / 3.0;  //此处提示波浪线
        if (i == 1)   max = s1;
        if (max.average < s1.average)
            max = s1;
    }
    printf("num:% d,name:% s,average:% .2lf\n", max.num, max.name, max.average);   //max.average中max提示未使用初始化内存
    return 0;
}
搜索更多相关主题的帖子: name average printf int max 
2022-02-26 13:01
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

struct student {
    int num;
    char name[10];
    int computer, english, math;
    double average;
};

int main( void )
{
    size_t n;
    printf( "Input number: " );
    scanf( "%zu", &n );

    struct student winner;
    puts( "Input the student's num, name and course scors." );
    for( size_t i=0; i!=n; ++i )
    {
        struct student tmp;
        printf( "No.%zu: ", i+1 );
        scanf( "%d%s%d%d%d", &tmp.num, tmp.name, &tmp.math, &tmp.english, & );
        tmp.average = (tmp.math + tmp.english + ) / 3.0;
        if( i==0 || winner.average <tmp.average )
            winner = tmp;
    }
    printf( "num:% d, name:% s, average:% .2lf\n", winner.num, winner.name, winner.average );
}
2022-02-26 16:52
CCCCW
Rank: 2
等 级:论坛游民
帖 子:8
专家分:27
注 册:2022-2-26
得分:0 
回复 2楼 rjsp
好厉害,本菜菜实在有很多不解
2022-02-27 10:00



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




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

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