1156 S Sequence II

SemiColon
By -
0
URI Online Judge | 1156

S Sequence II

Write an algorithm to calculate and write the value of S, S being given by:
S = 1 + 3/2 + 5/4 + 7/8 + ... + 39/?

Input

There is no input in this problem.

Output

The output contains a value corresponding to the value of S.
The value should be printed with two digits after the decimal point.
Input SampleOutput Sample


 Solution:


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


Tags:

Post a Comment

0Comments

Post a Comment (0)