0分,不知道哪里错了

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

W_X_D @ 2022-08-24 23:44:40

#include<iostream>
using namespace std;
int n, k, a, b;
double sum1, sum2;

int main()
{

    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++)
    {
        if(i % k == 0)
        {
             sum2 += i;
             a++;
         }
        else
        {
            sum1 += i;
            b++;
        }
    }
    printf("%.1f %.1f", sum1 / a, sum2 / b);
    return 0;
}

by 137QWQ @ 2022-08-24 23:52:37

printf("%.1f %.1f", sum2 / a, sum1 / b);


by myyyIisq2R @ 2022-08-24 23:57:26

printf("%.1f %.1f", sum2 / a, sum1 / b);


by windi @ 2022-08-25 16:59:23

把printf那行的sum1和sum2对调


by W_X_D @ 2022-11-05 14:15:04

@137QWQ 感谢!


by W_X_D @ 2022-11-05 14:15:38

@wangmingwei 感谢!


by W_X_D @ 2022-11-05 14:16:00

@windi 感谢!


|