URI Online Judge Solution 1156 S Sequence II using C, Python Programming Language.
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.
Solution Using C:
#include <stdio.h>
int main() {
int i,j=1;
float S=0;
for(i=1; i<=39; i+=2)
{
S += (float)i/(float)j;
j *= 2;
}
printf("%.2f\n",S);
return 0;
}
Comments
Post a Comment