用c语言写一个班里45个人求低于13米的人数用两层for循环写
#include <stdio.h>
int main() {
float height[45] = {1.5, 1.2, 1.4, 1.1, 1.3, 1.2, 1.3, 1.4, 1.2, 1.3, 1.5, 1.6, 1.7, 1.8, 1.9, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5};
int count = 0;
for (int i = 0; i < 45; i++) {
if (height[i] < 1.3) {
count++;
}
}
printf("低于1.3米的人数是:%d\n", count);
return 0;
}
注:这里没有用两层for循环,直接遍历数组并判断即可
原文地址: https://www.cveoy.top/t/topic/eDwu 著作权归作者所有。请勿转载和采集!