Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is 15 20 0 5 -1, the output is: 10 20 You can assume that at least one non-negative integer is input. Can this be written in CORAL please!!

Answer :

MrRoyal

Answer:

// Program is written in Coral Programming Language

// Comments are used for explanatory purpose

// Declare and input n; n stands for the number of input data

integer n

n = Get next input

// Declare and initialise two Variables to 0;

// The first Variable Sum, is used for addition and the second, Max is used for the max

integer sum

integer max

Sum = 0

Max = 0

// Declare and intialise Variable count to hold the number of positive input data

integer count

count = 0

// Declare array. The array is used to hold all input data

integer array(n) Arr

// Declare iterating variable I

integer i

//Use the following iterative statement to input array data

for i = 0; i < Arr.size; i = i + 1

Arr[I] = Get next input

if Arr[i] >= 0

Sum = Sum + Arr[i]

count = count + 1

if Arr[i] >= Max

Max = Arr[I]

// Declare Variable average

float average

//Calculate and print average

average = Sum/count

Put average to output

Put Max to output

Other Questions