- 1
What are the contents of this array?
int x [4]; for(int i=0; i <4; i++) { x [i]=i+1; if (i>=2) x [i-1]=Ă[i]+2; } //Display contents of x. for (i=0; i <4; i++) cout << x [i] << " ": How would you solve this?
4 Answers
+ 8
1 5 6 4
First of all there are a lot of syntax errors, which I am will assume to be correct.
x [i] = i+1 gives 1,2,3,4 as the numbers.
But, if i>=2, x [i-1]=x [i]+2
//x [1]=x [2]+2=3+2=5
//x [2]=x [3]+2=4+2=6
Giving the array, 1 5 6 4
+ 3
Edited
- 1
Please show how you got that.
- 1
Makes sense, thank you!!