求 大神。。哪错了

P1035 [NOIP2002 普及组] 级数求和

涵塘听雨 @ 2016-08-09 10:29:58

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>              //我把知道的都写上了
using namespace std;
int main()
{
   double n,k,i,sum=0;
    scanf("%d",&k);
    for(double n=1;;n++)
    {i=1/n;
     sum+=i;
     if(sum>k)
     {printf("%d",n);
      system("pause");
      return 0;
    }
    }
}

by 1124828077ccj @ 2016-08-09 12:41:07

@涵塘听雨 你确定double的变量能用%d输出?system要去掉


by white @ 2016-10-15 13:17:09

这是我写的

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

by xhx2011 @ 2023-07-07 19:55:15

大神double用%d???,system不要


by xhx2011 @ 2023-07-07 19:55:37

@涵塘听雨


|