救命!样例过了,但却是0分.......

P1035 [NOIP2002 普及组] 级数求和

CQU5S @ 2021-02-05 13:10:32


#include<bits/stdc++.h>
using namespace std;
int main(){
    double m=0,n,k;
    cin>>k;
    for(n=1;m<k;n++){
        m=m+(1/n);
    }
    cout<<n;
    return 0;
}

by CGDGAD @ 2021-02-05 13:12:44

1\textbf{.0}/n

by CQU5S @ 2021-02-05 13:14:31

#include<bits/stdc++.h>
using namespace std;
int main(){
    double m=1.0,n,k;
    cin>>k;
    for(n=1;m<k;n++){
        m=m+(1.0/n);
    }
    cout<<n;
    return 0;
}

这样?


by CQU5S @ 2021-02-05 13:15:30

Emmm...还是没过


by FCB_1899 @ 2021-02-05 13:18:38

@CQU5S n都是double了,n++肯定不好使啊


by CQU5S @ 2021-02-05 13:20:28

哦,谢谢ด้้้้้็้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็


by CQU5S @ 2021-02-05 13:23:21

好像还不对


by CQU5S @ 2021-02-05 13:25:11


#include<bits/stdc++.h>
using namespace std;
int main(){
    double m=0,n,k;
    cin>>k;
    for(n=1.0;m<k;n+=1.0){
        m=m+(1.0/n);
    }
    cout<<n;
    return 0;
}

by WanderingTrader @ 2021-02-05 13:29:41

@CQU5S 你把n和k都换成int


by BotDand @ 2021-02-05 13:32:43

m<=k


by CQU5S @ 2021-02-05 13:36:13

#include<bits/stdc++.h>
using namespace std;
int main(){
    double m=0.0;
    int n,k;
    cin>>k;
    for(n=1;m<k;n++){
        m=m+(1.0/n);
    }
    cout<<n;
    return 0;
}

还是不对


| 下一页