Question #285076

Write a program that ask the user of the number of elements in array and input


elements as much as the number of elements. Print the inputted elements and determine the


sum and average of the array. (You must input 10 elements and varying 3-digit numbers).


Expert's answer

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<script type="text/javascript">
	let sum = 0;
	let avrg = 0;
	let l = Number(prompt("number of elements"));
	let arr = new Array(l);
	for(let i=0; i<l; i++){
		arr[i] = Number(prompt("Enter array elements:"))}
	for(let i=0; i<l; i++){
		sum+=arr[i]};
	if (l > 0) {
		avrg = sum / l}
	document.write(`<p>inputted elements: ${arr}</p>`);
	document.write(`<p>sum: ${sum}</p>`);
	document.write(`<p>average: ${avrg}</p>`);
</script>	
</body>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS