Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function averageNumber(input) {
- let num = Number(input[0]);
- let index = 1;
- let sum = 0;
- while (index <= num) {
- sum += Number(input[index++]);
- }
- console.log(`${(sum / num).toFixed(2)}`);
- }
- РЕШЕНИЕ С FOR:
- function averageNumber(input) {
- let num = Number(input[0]);
- let sum = 0;
- for (let i = 1; i <= num; i++) {
- let number = Number(input[i]);
- sum += number;
- }
- console.log(`${(sum / num).toFixed(2)}`);
- }
Add Comment
Please, Sign In to add comment