cpp0分求助(大哭)

P1035 [NOIP2002 普及组] 级数求和

Southern26 @ 2023-03-29 19:50:14

#include<iostream>
using namespace std;
int main(){
    double n;
    cin>>n;
    int k=1;
    double sum=0;
    while(n>=1){
        sum+=1/n;
        n--;
}
        k=(int)(sum)+1;
        cout<<k;

    return 0;
}

by xbwn416772047 @ 2023-03-29 20:13:36

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

by pi3141592 @ 2023-03-29 20:27:05

缩进问题


|