Compute the Average

Sort by

recency

|

358 Discussions

|

  • + 0 comments

    !/bin/bash

    read n sum=0

    for (( i=0; i

    Calculate and print average rounded to 3 decimal places

    avg=sum / avg"

  • + 0 comments

    This problem is a great way to practice handling input, performing arithmetic operations, and formatting output in programming! 🖥️✨ Calculating the average and rounding it to three decimal places ensures precision, which is useful in real-world applications. Daman Games Online

  • + 0 comments

    readarray -t V len=echo ${V[0]} sum=0 unset V[0] for a in ((a)) done result=echo "scale=3;len" | bc -l echo $result

  • + 0 comments
    read N
    result=0 
    for ((i=0; i < N; i++)); do
      read number
      result=$(echo "$result + $number" | bc)
    done
    avg=$(echo "$result / $N"  | bc -l)
    printf "%0.3f" "$avg"
    
  • + 0 comments

    This question is a bunch of floating point rounding error bullshit. You got it right close enough for all real-world applications if you got all but 1 on the submission.