求助,自己做的结果是对的,但是全部WA

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

dongfengnrq @ 2021-10-24 23:08:53

#include<stdio.h>
int main()
{
    int n,k;
    int a,b;
    double ave1=0,ave2=0;
    scanf("%d%d",&n,&k);
    while(n>1) {
        if (n%k==0) {
            ave1=ave1+n;
            a++;
        }
        else {
            ave2=ave2+n;
            b++;
        }
        n--;
    }
    printf("%.1lf %.1lf",ave1/a,ave2/b);
    return 0;
}

by omemi @ 2021-10-25 00:54:45

@dongfengnrq 将

int a, b;

改成

int a = 0, b = 0;

by dongfengnrq @ 2021-10-25 19:54:43

@omemi 谢谢,但是改完了依然是WA


by omemi @ 2021-10-25 21:00:04

@dongfengnrq 将while(n > 1) 改成 while(n >= 1) 就行了


by dongfengnrq @ 2021-10-25 21:12:33

@omemi 这下可以了,谢谢大佬


|