Write a program that stores 10 values in an array of type integer. The array and its size are passed to the user defined function that finds the sum of all those values which are less than the average of all values of the array. The sum is displayed by the main function.
#include
using namespace std;
int sum(int arry[10], int size) {
int sum = 0;
float avg = 0;
for (int j = 0; j < size; j++) {
sum = sum + arry[j];
}
avg = sum / 10;
sum = 0;
for (int k = 0; k < size; k++) {
if (arry[k] < avg) {
sum = sum + arry[k];
}
}
return sum;
}
int main() {
int arry[10];
cout << "Enter Integer Values to array:";
for (int i = 0; i < 10; i++) {
cout << "\n" << i + 1 << ":";
cin >> arry[i];
}
cout << "\nThe Sum of numbers smaller than avg is: " << sum(arry, 10);
return 0;
}
See Also: Rectangle Class by Inheritance in C++

