PROBLEM 5
Easy

Average of Three Numbers

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#5

Given three numbers `a`, `b`, `c`, print their arithmetic mean.

EXAMPLE

Example

Input
3 6 9
Output
6.0

LIMITS

Constraints

The input sequence contains at most 100000 elements; numeric values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Average of Three Numbers

JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.

💡
NEED HELP? Hints
+

['Write the formula using named intermediate values if it contains more than one operation.', 'Before printing, output only the computed result and do not add explanatory text that is absent from the required format.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [a, b, c] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = (((a + b) + c) / 3);
console.log(Number.isInteger(result) ? result.toFixed(1) : result);