程序编译正确,运行不正常,请各位看看,谢啦。。。
代码如下:编译能通过,运行不正常,输入数值的时候没输入完就结束了,究竟什么原因??程序代码:
#include <stdio.h> #define N 5 struct student { int num; char name[20]; char sex; int score; }; int main(void) { struct student stu[N]; int i, Count_m = 0, Count_f = 0; for(i=0; i<N; ++i) { printf("Information No.%d\n", i+1); printf("Enter Num&Name:\n"); scanf("%d%s", &stu[i].num, &stu[i].name); /*输入学号和姓名*/ printf("Enter sex&score:\n"); scanf("%d%c", &stu[i].score, &stu[i].sex); /*输入成绩和性别*/ getchar(); } for(i=0; i<N; ++i) { if(stu[i].sex == 'M'||stu[i].sex == 'm') /*计算男生和女生的人数*/ Count_m++; else Count_f++; if(stu[i].score > 85) /*分数大于85,输出名字和分数*/ { printf("Name is %s\nScore is %d\n", stu[i].name, stu[i].score); } } printf("boys = %d, girls = %d\n", Count_m, Count_f); return 0; }