We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Linux Shell
- Bash
- Compute the Average
- Discussions
Compute the Average
Compute the Average
Sort by
recency
|
353 Discussions
|
Please Login in order to post a comment
Wrong Code uses integer arithmetic ($((sum + num))), which truncates floating-point numbers, leading to incorrect results when decimals are involved. For example, with inputs 1.5, 2.5, and 3.0, the sum becomes 6, resulting in an incorrect average of 2.000.
Correct code uses bc for all arithmetic, which handles both integers and floating-point numbers correctly. With the same inputs, the sum becomes 7.0, and the correct average of 2.333 i
(easy solution is here : and if you are fail in one test and pass 5 test it is because you are not useing %0.3f .else use this bigner code. :)