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.
#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;
}
Comments
Leave a comment