0

Why this code doesn’t work good?

#include <iostream> using namespace std; void invert(int *A, int i, int j){ if(&A[j]<&A[i]){ for(int k=0;k<i;k++){ cout<<A[k]<<" "; } } else{ return invert(A, i, j-1); cout<<A[j]<<" "; } } int main() { int dim, first, last; int A[100]; cin >> dim >> first >> last; for(int i = 0; i < dim; i++) { cin >> A[i]; } cout << "start" << endl; invert(A, first, last); cout << "end" << endl; } This code should give like output the array, but it should give back it inverted from the A[first] to A[last], for example if dim( dimension of the array)=4, first=1 and last=3 A[0]=1, A[1]=2, A[2]=3, A[3]=4; it should give 1 4 3 2.

7th Dec 2018, 2:50 PM
riccardo
2 Réponses
+ 1
now I’ve undertood, thanks you
7th Dec 2018, 4:57 PM
riccardo