求助,一直四十分,用了double也不行

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

MrEmao @ 2021-06-26 21:02:17

#include<stdio.h>
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int sum1=0,count1=0;
    int sum2=0,count2=0;
    int i;
    for(i=1;i<=n;i++){
        if(i%k==0){
            count2++;
            sum2+=i;
        }
        else{
            count1++;
            sum1+=i;
        }
    }
double aver1=(double)(sum1/count1);
double aver2=(double)(sum2/count2);
printf("%.1f %.1f",aver2,aver1);
}

by Plozia @ 2021-06-26 21:16:08

@MrEmao

把下面这两句话:

double aver1=(double)(sum1/count1);
double aver2=(double)(sum2/count2);

改成:

double aver1=(double)sum1/count1;
double aver2=(double)sum2/count2;

by MrEmao @ 2021-06-27 08:27:54

@Plozia 明白了,谢谢


|