0
C++ question from array
given an array consisting of N elements. Create a program that displays mass elements in a quid. [0], ə[n-1], ə[1], ə[n-2], ə[2], ə[n-3],... in c++
3 odpowiedzi
0
Are those indices inside the square brackets?
You can probably setup a left and right side index, increment left index and decrement right index as you go iterating the array.
0
here is bòladi in this view, input n=4,
a[0]=7
a[1]=3
a[2]=9
a[3]=4
if and what is said in the condition a [n-1]=a [4-1]
Output
a[o],a[n-1],a[1], a[n-2]...=7,4,3,9,9,3,4,7
in appearance, the condition must be met
0
#include<iostream>
using namespace std;
int main(){
int n,i;
cout<<"n=";cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
if(n%2==0)
cout<<a[n-1-i]<<" ";
}return 0;
}