82.9k views
0 votes
Write a program that hardcodes N and then computes the average (the arithmetic mean) of N integers selected from [0,1000]. This program should run 10 times, and thus provide 10 results.

You should use an outer loop that runs the inner loop (the one which computer the mean) a total of 10 times, printing out the 10 results, one per line.

User JoseBazBaz
by
3.1k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

Program ( PascalABC) and Result:

const N = 25;

var Summ : integer;

Num : integer;

Sa : real;

begin

Num := 0;

for var j := 1 to 10 do

begin

Summ := 0;

for var i:= 1 to N do

Summ := Summ + Random (1001);

Sa := Summ / N;

Write (' Sa = ', Sa);

WriteLn;

end;

end.

With p = 1 000 000 the result is naturally close to the middle of the interval (0 - 1000), that is, the number 500

Write a program that hardcodes N and then computes the average (the arithmetic mean-example-1
Write a program that hardcodes N and then computes the average (the arithmetic mean-example-2
User Pavel F
by
3.4k points