解题思路:
注意事项:
参考代码:
#include<stdio.h>
int main()
{
int n, a[100], i;
float sum_1 = 0.0, sum_2 = 0.0, sum_3 = 0.0, sum_4 = 0.0;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++)
{
if (a[i] <= 18 && a[i] >= 0)
sum_1+=1.0;
else if (a[i] >= 19 && a[i] <= 35)
sum_2+=1.0;
else if (a[i] >= 36 && a[i] <= 60)
sum_3+=1.0;
else if (a[i] >= 61)
sum_4+=1.0;
}
printf("%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%\n",100.0* sum_1 / (float)n, 100.0*sum_2 / (float)n, 100.0*sum_3 / (float)n, 100.0*sum_4 / (float)n);
return 0;
}
0.0分
0 人评分