大神们请教一下C++运行后显示debug assertion failed

#include <stdio.h>#include<math.h>#define N 3struct student{ int num; char name; float chinese; float english; float math; float total;}st[N];float sum_out(struct student *p, int i){ st[i].total = p->chinese + p->english + p->math; return st[i].total}int main(){ int i; printf("输入学号 姓名 语文 英语 数学\n"); for (i = 0; i <= N; i++) { scanf("%d %s %f %f %f",&st[i].num,& st[i].name, &st[i].chinese, &st[i].english, &st[i].math); } printf("输出数据:学号 姓名 总分\n "); for (i = 0; i < =N; i++) { //st[i].total = st[i].chinese + st[i].english + st[i].math; stotal = sum_out(&st[i], i); printf("%d %s %5.1f ", st[i].num, st[i].name,stotal); }}可正常编译,在填写第一行学生的数据后,回车会弹出如下

#include <stdio.h>
#include<math.h>
#define N 3
struct student{
    int num;
    char name[10];
    float chinese;
    float english;
    float math;
    float total;
}st[N];
float sum_out(struct student *p){
    p->total = p->chinese + p->english + p->math;
    return p->total;
}
int main(){
    int i;
    printf("输入学号 å§“名 è¯­æ–‡ è‹±è¯­ æ•°å­¦\n");
    for (i = 0; i < N; i++) {
        scanf("%d %s %f %f %f",&st[i].num, &st[i].name, &st[i].chinese, &st[i].english, &st[i].math);
    } 
    printf("输出数据:学号 å§“名 æ€»åˆ†\n ");
    for (i = 0; i < N; i++) {
        sum_out(&st[i]);
        printf("%d %s %5.1f \n", st[i].num, st[i].name, st[i].total);
    }
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜