Answer to Question #181188 in C++ for luna

Question #181188

Create an application containing an array that stores 10 integers. The application should call five methods that in turn:

a) Display all integers in the array

b) Display all integers in reverse order

c) Display the sum of the integers

d) Display all values that ae high  than the calculated average value



1
Expert's answer
2021-04-16T08:16:22-0400
#include <iostream>
using namespace std;
void Display(int x[10]){
    cout<<"\nThe digits in the order they were input are; \n";
    for(int i = 0; i < 10; i++){
        cout<<x[i];
        if(i != 9) cout<<", ";
    }
    cout<<endl;
}
void DisplayReverse(int x[10]){
    cout<<"\nThe digits displayed in reverse are; \n";
    for(int i = 9; i >= 0; i--){
        cout<<x[i];
        if(i != 0) cout<<", ";
    }
    cout<<endl;
}
int DisplaySum(int x[10]){
    int sum = 0;
    for(int i = 0; i < 10; i++) sum += x[i];
    cout<<"\nThe total of the integers is "<<sum<<endl;
    return sum;
}
void DisplayHigherThanAverage(int x[10]){
    float average = (float)DisplaySum(x) / 10;
    cout<<"\nThe integers higher than average are;\n";
    for(int i = 9; i >= 0; i--){
        if(i != 0 && x[i] > average && i != 9) cout<<", ";
        if(x[i] > average) cout<<x[i];
    }
    cout<<"\n\n";
}
int main(){
    int x[10];
    cout<<"Input 10 integers; \n";
    for(int i = 0; i < 10; i++){
        cin>>x[i];
    }
    Display(x);
    DisplayReverse(x);
    DisplayHigherThanAverage(x);
    return 0;
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS