write a program to input 5 integer numbers in an array. As each number is input, add the numbers to a total. After all numbers are input, display the numbers, their total, and their average.
1
Expert's answer
2013-04-09T11:10:13-0400
#include <iostream>
using namespace std;
void input_array(int* array, int arraySize) { cout << "Input an array of " << arraySize << " elements: "; for (int c = 0; c < arraySize; c++) cin >> array[c]; }
int calc_total(int* array, int arraySize) { int result = 0; for (int c = 0; c < arraySize; c++) result += array[c]; return result; }
void print_array(int* array, int arraySize) { cout << "Array elements:"; for (int c = 0; c < arraySize; c++) cout << " " << array[c]; cout << endl; }
int main() { int array[5]; input_array(array, 5); print_array(array, 5); cout << "The sum of array elements is: " << calc_total(array, 5) << endl; cout << "The average value of array elements is: " << calc_average(array, 5) << endl; return 0; }
Comments
Leave a comment