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.
1
Expert's answer
2013-04-08T08:22:32-0400
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; }
Comments
Leave a comment