0
Array question
what is the output of this code? int nums[] = {1, 3, 2, 4, 6}; if (nums [2] > nums [0]) nums [0] = nums [2]; else nums [0] = nums [4]; cout << (nums [0] + nums [2] + nums [3]) guys can someone please explain to me how the h*ll can output be 8?.. if nums [0] = num [4] = 6 nums [2] = 2 and nums [3] = 6, the output I get is 14!? cheers!
2 Answers
+ 4
nums[2] is 2
nums[0] is 1
if(2 > 1) returns true -> num[0] = nums[2] = 2
Your array looks now: 2, 3, 2, 4, 6
nums[0] + nums[2] + nums[3] = 2 + 2 + 4 = 8
output: 8
+ 3
thanx a bunch Denise...I thought that else statement was false so I calculated if statement!
SoloLearn Q&A is faster then my IDE ;)