+ 1

Not getting the expected output.

I expected the output to be 2 but I'm getting a 3 instead. static int Find(int n) { int z = n - 1; int[] a = new int[4]; for(int i = 0; i < 4; i++) { a[i] = i + 2; } return a[z]; } static void Main(string[] args) { Console.WriteLine(Find(2)); } } }

4th Jul 2018, 2:28 PM
Julian Aung
Julian Aung - avatar
1 Resposta
+ 7
It's supposed to be 3. Find (2) => So z = 2-1 = 1 Since a[i] = i+2, inside the loop a[1] becomes 1+2 = 3
4th Jul 2018, 2:33 PM
Shamima Yasmin
Shamima Yasmin - avatar