麻烦大家看下这个60分qwq

P1035 [NOIP2002 普及组] 级数求和

蟹萌嘉ovo @ 2018-08-16 21:24:44

include<cstdio>

int main(){

int k,n;
double sum;
scanf("%d",&k);
for(int i=1;i<=n;i++){
    sum+=1.0/i;
    if(sum>k){
        printf("%d",i);
        break;
    }
}
return 0;

}


by yzx72424 @ 2018-08-16 21:31:33

@蟹萌嘉ovo 你的n...


by yzx72424 @ 2018-08-16 21:31:59

没赋值..都能过60分


by 周子衡 @ 2018-08-16 21:32:53

for(int i=1;i<=n;i++)

中的i<=n去掉或者直接用while while会好一些


by yzx72424 @ 2018-08-16 21:33:28

或者n赋值1e9


by chenjianye @ 2018-08-16 21:33:46

for(int i=1;i<=n;i++)

n 是设么


by chenjianye @ 2018-08-16 21:34:27

#include <stdio.h>
int main()
{
    int n=0,k;
    double sn=0;
    scanf("%d",&k);
    while(sn<=k)
    {
        n++;
        sn+=1.0/n;

    }
    printf("%d",n);
    getchar();
    return 0;
}

代码


by 蟹萌嘉ovo @ 2018-08-17 18:41:20

@yzx72424 十分感谢!


by 蟹萌嘉ovo @ 2018-08-17 18:41:44

@周子衡 好的十分感谢


by 蟹萌嘉ovo @ 2018-08-17 18:42:01

@chenjianye 十分感谢!


|