40分,求助大佬们

P5719 【深基4.例3】分类平均

wdmzjhyk @ 2024-10-29 11:16:46

#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
int main()
{
    int n, k,a1=0,a2=0;
    float sum1=0,sum2=0;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0)
        {
            a1++;
            sum1 += i;
        }
        else if(i%k!=0)
        {
            a2++;
            sum2 += i;
        }
    }
    printf("%.1f %.1f",sum1/a1,sum2/a2);
    return 0;
}

|