Answer to Question #198114 in C++ for Soh

Question #198114

Write a program that initialzies an array with 10 random integers in the range from 1 to 99 inclusive and then prints the following two lines of output: 

• Every element at even index all on the same line separated by a space. 

• Only the first and the last element on the same line separated by a space.


1
Expert's answer
2021-05-25T00:09:22-0400
#include <iostream>


using namespace std;


int main()
{
    int arr[10];
    for (int i=0;i<10;i++){
        arr[i]=(rand() % 99) + 1;
        //Every element at even index all on the same line separated by a space.
        if (i%2==0){
            cout<<arr[i]<<" ";
        }
    }
    //Only the first and the last element on the same line separated by a space.
        cout<<"\n"<<arr[0]<<" "<<arr[9];
    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