#include <stdio.h>

int main() {
    FILE *inputFile, *outputFile;
    float num;
    int count = 0;
    float sum = 0;

    inputFile = fopen("data.txt", "r");
    if (inputFile == NULL) {
        printf("无法打开输入文件\n");
        return 1;
    }

    while (fscanf(inputFile, "%f", &num) == 1) {
        count++;
        sum += num;
    }

    float average = sum / count;

    fclose(inputFile);

    outputFile = fopen("result.txt", "w");
    if (outputFile == NULL) {
        printf("无法打开输出文件\n");
        return 1;
    }

    inputFile = fopen("data.txt", "r");

    int i = 0;
    while (fscanf(inputFile, "%f", &num) == 1) {
        fprintf(outputFile, "%.2f ", num);
        i++;
        if (i == 5) {
            fprintf(outputFile, "\n");
            i = 0;
        }
    }

    fprintf(outputFile, "\n实数个数：%d\n平均值：%.2f", count, average);

    fclose(inputFile);
    fclose(outputFile);

    return 0;
}
