C求助 救命 为什么又是零分

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

Azure_lyn @ 2022-04-03 11:43:29


#include<stdio.h>
int main()
{
    int i,n,k,k1,k2,a1,a2;
    double sum1,sum2;
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++)
    {
        if (i%k==0)
        {sum1=sum1+i;k1++;}
        else
        {sum2=sum2+i;k2++;}
    }
    a1=((int)(sum1/k1+0.5)*10)/10;
    a2=((int)(sum2/k2+0.5)*10)/10;
    printf("%.1lf %.1lf",a1,a2);
    return 0;
}

by SHI250011 @ 2022-08-29 13:30:20

附上我的代码```c

include <stdio.h>

int main(void) { int n,k; scanf("%d %d",&n,&k);

double a=0,b=0; int c=0,d=0; for(int i=0;i<=n;i++) { if(i%k==0) { a+=i; c++; } else if(i%k!=0) { b+=i; d++; } }

printf("%0.01lf %0.01lf",a/(c-1),b/d); return 0; }


|