The proportion of the total number of patients in four age groups prevalence statistics.

Description questions
Want to run a hospital to get an illness whether or not related to age, the need for consolidation in the diagnosis of previous records, according to 0-18,19-35,36-60,61 above (including 61) Statistical four age groups the proportion of the total number of cases of illness.
Input Format
Of 2 rows, the number of patients in the past behavior of the first n (0 <n <= 100), the second age at the behavior of each sick patients.
Output Format
0-18,19-35,36-60,61 according to the above (including 61) Age four output ratio of the total number of the segment number of cases of illness, the output as a percentage, accurate to two decimal places. Each age group accounted for one line, a total of four lines.
Sample input
10
1 11 21 31 41 51 61 71 81 91
Sample Output
20.00%
20.00%
20.00%
40.00%
#include <stdio.h>
int main()
{
    int n,x,i,a,b,c,d;
    double sum;
    while(scanf("%d",&n)!=EOF){
        a=0; b=0; c=0; d=0;
        for(i=0;i<n;i++){
            scanf("%d",&x);
            if(x<=18) a++;
            if(x>=19&&x<=35) b++;
            if(x>=36&&x<=60) c++;
            if(x>=61) d++;
        }
        sum=a+b+c+d;
        printf("%.2lf%%\n",a*(100/sum));
        printf("%.2lf%%\n",b*(100/sum));
        printf("%.2lf%%\n",c*(100/sum));
        printf("%.2lf%%\n",d*(100/sum));
    }
    return 0;
}

Published 32 original articles · won praise 9 · views 70000 +

Guess you like

Origin blog.csdn.net/yi__cao/article/details/78515719