这个C语言怎么回事?总是出现不了order=1的情况,上来就从order=2开始

来源:百度知道 编辑:UC知道 时间:2024/05/19 00:14:35
/* Note:Your choice is C IDE */
#include "stdio.h"
#define M 5
void main()
{int i,n,m,j,b[M],temp;
float s1_ave,s2_ave,s3_ave,s1_sum=0.0,s2_sum=0.0,s3_sum=0.0;
struct student
{char stn[5];
int s1;
int s2;
int s3;
int ave;
int ord;}stu[M];
printf("This programe is designed to caculate 20 students' scores on 3 subjects,\n");
printf("it will output everyone's message and their average score of the 3 subjects,\n");
printf("and the average score of the 20 students on every one of the 3 subjet.\n");
printf("\n");
printf("Now please input the 20 students' basic information, you can input on the order:\n");
printf("student number(4 numbers) score of the 3 subjects\n");
printf("the forty(four for per student) elements should be inputted with space between each others\n

for(m=1;m<=M;m++)
{for(i=0;i<=(M-1);i++)
if(stu[i].ord==m)
printf("number:%s,subject 1:%d,subject 2:%d,subject 3:%d,average:%d,order:%d\n",stu[i].stn,stu[i].s1,stu[i].s2,stu[i].s3,stu[i].ave,stu[i].ord);}
问题在这里.当if的条件不满足时,下面语句不执行,内循环就结束了.应该加一句控制else continue;以使内循环执行完.
for(i=0;i<=(M-1);i++)
s1_sum+=stu[i].s1;
s1_ave=s1_sum/M;
for(i=0;i<=(M-1);i++)
s2_sum+=stu[i].s2;
s2_ave=s2_sum/M;
for(i=0;i<=19;i++) 对了.这里i<=19是怎么回事?
s3_sum+=stu[i].s3;
s3_ave=s3_sum/M;