67 172
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #27097 in Other Programming & Computer Science for victor

Question #27097
this is in pseudocode

Write a program using loops, conditionals, and file processing concepts. Write a main module, two subprograms, and one function based on an array input by the user.

Input a list of positive numbers (terminated by 0) into an array, find the mean (average) of the numbers in the array, and output the result. Use a subprogram to input the numbers, a function to find the mean, and a sub-program to output the result.
Expert's answer
procedure input_arr(file_name, a[])
{
file = open_file_for_reading(file_name);
i = 0;
do {
read_from_file(file, a[i]);
i = i + 1;
} while (a[i] != 0)
close_file(file);
}

function mean(a[]) {
sum = 0;
i = 0;
while (a[i] != 0) {
sum = sum + a[i];
i = i + 1;
}
return sum / i;
}


procedure output_num(file_name, number)
{
file = open_file_for_writing(file_name);
write_to_file(file, number);
close_file(file);
}


main()
{
a[] = empty_arr();
input_arr("input.txt", a);
output_num("output.txt", mean(a));
exit();
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions