Answer to Question #165726 in C++ for Kefilwe Mamabolo

Question #165726

An array called number contains 20 integer values and must be filled with values in the 

following way:

 Fill the array with consecutive even numbers starting from 10. 

 Start again at the first element and increase every fourth element with 3.

 Replace the value of the first four elements each with its square.

 Deduct 2 from the last 3 elements.

 Swap the value of element 5 and element 15.

 Add the value of the first element to that of the last element

 Add consecutive integers (starting from 1) to all even elements.

Remember, the first element has a subscript of 0 and the last element (element 20) 

has a subscript of 19.

The following must be displayed:

 All elements must be displayed each on a new line. Identify each element clearly.

 Display the highest value in the array.

 The lowest value in the array must be displayed.

 Count and display how many even values and how many odd values the array 

contains.


1
Expert's answer
2021-02-23T16:11:54-0500
#include<iostream>
using namespace std;
int main(){
 int numbers[20];
 int i,a=10;
 int sum=0;
 for(i=0;i<=20;++i){
    
numbers[i]=a;
 sum=sum+numbers[i];

 a=a+2;
 }

for(i=0;i<=20;++i){

    if( i%4==0){
    
    numbers[i]=numbers[i]+3;
    
    
    }
    if(i<=4){
numbers[i]=numbers[i]*numbers[i];
    
    }



    if(i>=16){
numbers[i]=numbers[i]-3;
    
    }


 }
int temp=numbers[5];
numbers[5]=numbers[15];
 numbers[15]=temp;
numbers[19]=numbers[0];


for(i=0;i<=20;++i){


cout<<numbers[i]<<endl;
cout<<"sum="<<sum<<endl;
}

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