Cities temperature

City Temperature: 10 city name and its existing spring, summer, autumn and winter the average temperature of the four seasons, write procedures, appropriate definition of the structure, enter the name of the 10 cities and the Four Seasons temperature, calculated in various cities throughout the year the average temperature, and output the name of the city from low to high order according to the average temperature, the temperature of the seasons and the annual average temperature.

#include <stdio.h>

struct s {
    char c[10];
    float a[5];
};

void main() {
    struct s x[10], t;
    int i, j;
    for (i = 0; i < 10; i++) {
        scanf("%s%f%f%f%f", x[i].c, &x[i].a[0], &x[i].a[1], &x[i].a[2], &x[i].a[3]);
        x[i].a[4] = (x[i].a[0] + x[i].a[1] + x[i].a[2] + x[i].a[3]) / 4;
    }
    for (i = 0; i < 10 - 1; i++)
        for (j = 0; j < 10 - 1 - i; j++)
            if (x[j].a[4] > x[j + 1].a[4]) {
                t = x[j];
                x[j] = x[j + 1];
                x[j + 1] = t;
            }
    for (i = 0; i < 10; i++) {
        printf("%s,%f,%f,%f,%f,%f\n", x[i].c, x[i].a[0], x[i].a[1], x[i].a[2], x[i].a[3], x[i].a[4]);
    }
}
Published 139 original articles · won praise 4 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104808052