Sunday, 27 March 2016

Solution of URI 1156 :: S Sequence II


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    double a,b=1,c, S=0;
    for(a=1; a<=39; a+=2)
    {
        c=a/b;
        S+=c;
        b*=2;
    }
    printf("%.2lf\n",S);
    return 0;
}

4 comments:

  1. #include
    #include
    int main()
    {
    double i,z=0.0;
    for(i=0;i<=19;i++)
    {
    z = z + ((2.0i+1)/pow(2.0,i));
    }
    printf("%.2lf",z);
    return 0;
    }

    what's wrong in this code?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. #include
    int main()
    {
    int i,n,j,sum=0;
    scanf("%d",&n);
    while(n!=0)
    {
    if(n%2==0)
    n=n;
    else
    n=n+1;
    for(j=1;j<=5;j++)
    {
    sum+=n;
    n=n+2;
    }
    printf("%d\n",sum);
    n=0;
    sum=0;
    scanf("%d",&n);
    }
    return 0;
    }



    reply...

    ReplyDelete
  4. #include
    #include
    int main()
    {
    int i,x,j=2,count=0;
    float sum=1;
    for(i=3;i<=39;i=i+2)
    {
    count++;
    x=pow(j,count);
    sum=sum+(i/(float)x);
    }
    printf("%.2f\n",sum);
    return 0;
    }

    reply..

    ReplyDelete

Note: only a member of this blog may post a comment.