0分???

P1035 [NOIP2002 普及组] 级数求和

JRzyh @ 2019-09-08 20:11:26

include<bits/stdc++.h>```cpp



using namespace std;
int main()
{
    double sum=0;
    int a=0,n=0;
    cin>>a;
    do
    {
        n++;
        sum=0;  
        for(int i=0;i<n;i++)
        {
            sum=sum+1.0/i;
        }

    }
    while(sum<=a);
    cout<<n;
    return 0;
}

by tidongCrazy @ 2019-09-08 20:12:02

希望更丰富的展现?使用Markdown


by Nicoppa @ 2019-09-08 20:14:15

@Zhaoyuhang2008 您加了两遍1吧..


by D447H @ 2019-09-08 20:15:31

#include<iostream>
using namespace std;
int K; 
double S=0.0,i=1.0; 
int main() { 
    cin>>K; 
    while(S<=K) { 
        S=S+(1/i); 
        i=i+1; 
    } 
    cout<<i-1; 
    return 0; 
}

AC代码


by JRzyh @ 2019-09-08 20:42:19

thanks!谢谢各位


|