Write an application that reads 20 numbers into an array. Calculate the average of the sed number entered as well as the average of the even numbers entered. Display the average of both odd and even numbers and all numbers entered into the array.
(Implement this using function).
1
Expert's answer
2016-01-19T08:28:40-0500
Answer on Question#56520 — Programming — C++
#include <iostream> using namespace std;
double calculate_odd_average(int array[], int size) { int sum=0; int count=1; for(int i=0; i<size; i++) { if(array[i]%2==1) { sum+=array[i]; count++; } } return (double)sum/count; }
double calculate_even_average(int array[], int size) { int sum=0; int count=1; for(int i=0; i<size; i++) { if(array[i]%2==0) { sum+=array[i]; count++; } } return (double)sum/count; }
double calculate_all_average(int array[], int size) { int sum=0; for(int i=0; i<size; i++) { sum+=array[i]; } return (double)sum/size; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment