- 1

Plz, help me , guys !!!

Given an array A size N. Output its elements in the following order: A1,A2,AN,AN-1,A3,A4,AN-2,AN-3,...

3rd Nov 2017, 6:20 PM
канал JoE
канал JoE - avatar
3 odpowiedzi
+ 5
maybe something like this could work: int counter=0; for (int i =1;i<=N;i++){ cout<<<A[i]; if (i%2==0){ cout<<<A[N-counter++]; cout<<<A[N-counter++]; } }
3rd Nov 2017, 6:34 PM
seamiki
seamiki - avatar
+ 2
By A1 and AN I'm assuming you mean A1 to be the first element in the array and AN to be the last. Otherwise, if you mean for 1 and N to be the indexes then you'd be getting the second element and whatever garbage is in memory at the address just after the end of the array. Remember arrays are zero based and the last index of an array is the array length minus 1. So, you may want: A0,A1,AN-1,AN-2,A2,A3,AN-3,AN-4 etc instead. Something like this may work for you then: for(int i = 0; i < N/2; i+=2) { cout << A[i] << " ," << A[i+1] << " ,"; cout << A[N-1-i] << " ," << A[N-1-(i+1)] << " ,"; }
3rd Nov 2017, 7:58 PM
ChaoticDawg
ChaoticDawg - avatar
0
does your mother know????
3rd Nov 2017, 7:59 PM
Oma Falk
Oma Falk - avatar