Advertisement
Nina-S

Min Max Sum Average - JavaScript

Sep 26th, 2021
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let n = +gets() //4
  2.  
  3. let max;
  4. let min;
  5. let sum = 0;
  6. let avg = 0;
  7.  
  8. for (let i = 1; i <= n; i++) {
  9.     let next = +gets()
  10.     let current = next
  11.     sum = sum + next
  12.  
  13.     if (i === 1) {
  14.         max = current
  15.         min = current
  16.     }
  17.  
  18.     if (current > max) {
  19.         max = current
  20.     }
  21.     else if (current < min) {
  22.         min = current
  23.     }
  24. }
  25.  
  26. avg = sum / n;
  27.  
  28. print(`Min = ${min.toFixed(2)}`)
  29. print(`Max = ${max.toFixed(2)}`)
  30. print(`Sum = ${sum.toFixed(2)}`)
  31. print(`Avg = ${avg.toFixed(2)}`)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement