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

#include<stdio.h>#include<math.h>#defineN3structstudent{intnum;charname;floatchinese;... #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); }}可正常编译,在填写第一行学生的数据后,回车会弹出如下 展开
 我来答
匿名用户
2018-03-02
展开全部
#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);
    }
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式