冥思苦想也不为什么只得了60分

P1035 [NOIP2002 普及组] 级数求和

willxiao @ 2020-08-28 16:52:17

#include<iostream>
using namespace std;
int main(){
    float Sn=0;
    int k,n=0;
    cin>>k;
    while(Sn<=k){
    ++n;
    Sn+=(1.0/n);
    }
    cout<<n;
    return 0;
}

by 寒冰大大 @ 2020-08-28 16:54:15

double?


by 小辣椒嘿嘿 @ 2020-08-28 16:54:39

float精度不够,用double


by Steven__Chen @ 2020-08-28 16:54:54

开double试试


by pocafup @ 2020-08-28 16:55:19

亲测double可过


by CarroT1212 @ 2020-08-28 16:55:38

用double,float撑不住精度 (我个傻子看错了


by CLCK @ 2020-08-28 17:09:43

@willxiao

float改double

以后最好别用float


by willxiao @ 2020-08-28 17:17:15

@寒冰大大 谢谢指导


by willxiao @ 2020-08-28 17:17:59

@clock钟0622 谢谢指导


by liuzimingc @ 2020-11-01 18:58:21

@willxiao

#include<cstdio>
#include<cmath>
int main(){
    int k,i=0;
    double tot=0;
    scanf("%d",&k);
    while (tot<=k)
    {
        i+=1;
        tot+=1.0/i;
    }
    printf("%d",i);
    return 0;
}

我是这样的


|