第6章简单构造数据类型精要.ppt

第6章简单构造数据类型精要

6.7 综合案例 【案例6.17】9个人的成绩存放在score数组中,计算出平均分,并将低于平均分的分数放在below所指的数组中。 例如:当score数组中的数据为:10﹑20﹑30﹑40﹑50﹑60﹑70﹑80﹑90时,函数返回的人数应该是4,below中的数据应为:10﹑20﹑30﹑40。 案例分析: 用一维数组存放相应的分数段人数 具体程序如下: #include “stdio.h” #include “string.h” main( ) { int i, below [9], j,sum,avg,n; int score[9; for(i=0;i9;i++) scanf(%d,score[i]); /*输入9个成绩,放入数组中*/ for(i=0,sum=0;i9;i++) sum+=score[i]; avg=sum/9; for(i=0,n=0,j=0;i9;i++) if(score[i]avg) { n++; below[j]=score[i]; j++; } printf(the average score=%d\n,avg); /*输出平均成绩*/ printf (\nBelow the average score are:); for (i=0;in;i++) printf(%d ,below[i]); /

文档评论(0)

1亿VIP精品文档

相关文档