Back to Problem Solutions forum
I am not able to get the same decimals which are presented in the answer of this problem.
Answer should contain the processed sequence. All values should be calculated to precision of 1e-7 or better.
The average is calculated only with three values.
Probably it will help if you post an example of your answer and one given by problem checker after unsuccessful attempt. We can then discuss whether it is about accuracy or some minor algorithmic flaw spoils your solution.
my answer: 30.0000000 33.8333321 39.6333351 45.8999977 49.2333374 49.5000000 48.9666634 43.6000023 42.6333313 39.7666664 38.6666679 34.1333313 29.0666656 25.5000000 17.2666664 9.1999998 6.0999999 7.1333337 10.0333328
system's answer: 30.0 33.8333333333 39.6333333333 45.9 49.2333333333 49.5 48.9666666667 43.6 42.6333333333 39.7666666667 38.6666666667 34.1333333333 29.0666666667 25.5 17.2666666667 9.2 6.1 7.13333333333 10.0333333333
only for first few terms.
problem #20 I don't know how to stop reading a string input using loop or otherwise.
> problem #20 I don't know how to stop reading a string input using loop or otherwise.
In C
there is a handy fgets function. You only need to prepare long enough buffer and then read the whole string into it at once.
BTW if you use C
I dare to recommend the book C Programming Language
by Kernighan and Ritchie. Its updated edition is freely downloadable I believe. I myself learned by it. :)
(You can post questions about the language in separate threads in dedicated branch of forum so that people can react quicker.)
> my answer: 30.0000000 33.8333321 39.6333351
As for your original problem I think you are using float
variables and it has less accuracy. If it is the case, try changing to double
. Also if you print values with printf
you can output more digits by specifying something like this:
printf("%.9f", value)
this will try to print up to 9
digits after decimal point.