小数点后只有0

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

FYH666666 @ 2023-10-18 17:25:32

#include<stdio.h>
int main(){
    double sum1=0,sum2=0,cnt1=0,cnt2=0,z1=0,z2=0;
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        if(i%k==0){
            cnt1=cnt1+i;
            z1++;
        } 
        else{
            cnt2=cnt2+i;
            z2++;
        } 
    }
    sum1=1.0*cnt1/z1;
    sum2=1.0*cnt2/z2;
    printf("%.1lf %.1lf",sum1,sum2);
    return 0;
}

by ZhongYuLin @ 2023-10-18 17:37:31

不是过了吗……


by FYH666666 @ 2023-10-18 17:44:26

@ZhongYuLin eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.....................................................


by liyihan110210 @ 2023-11-05 22:28:59

这个不是对的吗?


|