sum+=1.0/i与1/i区别?

P1035 [NOIP2002 普及组] 级数求和

LiGeng2000 @ 2020-02-07 10:46:56

for(i=1;sum<=k;i++){
    sum+=1.0/i;/*why 1就 过不了,但是1.0就 能过?*/ 
}

by HaveFun @ 2020-02-07 10:47:42

stO 切红题的神仙


by Rainbow_qwq @ 2020-02-07 10:48:03

@LiGeng2000 double除的时候用1.0


by 嫐嬲巭孬 @ 2020-02-07 10:48:29

1.0实数,1整数


by Laser_Crystal @ 2020-02-07 10:48:45

1/i是整数除法,除出来就是整数

1.0/i是浮点数除法,除出来就是小数


by Magallan_forever @ 2020-02-07 10:50:25

@LiGeng2000 1的话是整数除法,就是0


by LiGeng2000 @ 2020-02-07 10:54:01

@Lattle_Car 理解了,谢谢❤


by LiGeng2000 @ 2020-02-07 10:54:41

@AT是女孩子 明白了,谢谢您!


by StudyingExample @ 2020-02-07 10:55:23

@LiGeng2000 double 浮点数!


|