为啥不对?应该对呀。求dalao解答。

P1035 [NOIP2002 普及组] 级数求和

duyh1114 @ 2017-10-29 14:16:45

#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) 
{
    int k;//k为输入整数 
    long n,i=1,l=0;//n是输出整数,m为保存点  
    long double s[999999], m=0;
    s[0]=1;
    for(i=1;i<=999999;i++)
    {
        s[i]=s[i-1] + 1.0/(i+1);
        if(s[i] > 15)
        {
            printf("alkjfdasdlkfasdf"); 
        } 
    }
    scanf("%d",&k);
    for(m=0;m<=k;)
    {
        m = s[l];
        l++;
    }
    if(m>k)
    {
        n=l;
        printf("%d",n);
    }
    return 0;
}

by duyh1114 @ 2017-10-29 14:17:44

补充一下,80,第三个错了。


by duyh1114 @ 2017-10-29 14:19:02

改一下,

#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) 
{
    int k;//k为输入整数 
    long n,i=1,l=0;//n是输出整数,m为保存点  
    long double s[999999], m=0;
    s[0]=1;
    for(i=1;i<=999999;i++)
    {
        s[i]=s[i-1] + 1.0/(i+1);
    }
    scanf("%d",&k);
    for(m=0;m<=k;)
    {
        m = s[l];
        l++;
    }
    if(m>k)
    {
        n=l;
        printf("%d",n);
    }
    return 0;
}

|