编辑代码

#include <stdio.h>

int main() {
    int month, duration;
    float cost;
    float total_cost = 0;
    
    for (month = 1; month <= 12; month++) {
        printf("请输入第%d个月的通讯时长(单位:分钟):", month);
        scanf("%d", &duration);

        if (duration <= 100) {
            cost = 28;
        } else if (duration <= 200) {
            cost = 28 + (duration - 100) * 0.3;
        } else {
            cost = 28 + 100 * 0.3 + (duration - 200) * 0.15;
        }

        total_cost += cost;

        printf("第%d个月的资费为:%.2f元\n", month, cost);
    }

    printf("该年资费的总和为:%.2f元\n", total_cost);

    return 0;
}