I have an array a. a[Math.Abs(a[i])-1] = -a[Math.Abs(a[i])-1]. What it is doing?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have an array a. a[Math.Abs(a[i])-1] = -a[Math.Abs(a[i])-1]. What it is doing??

please help trying to understand something

28th Jun 2018, 11:55 AM
ayushi lahariya
ayushi lahariya - avatar
5 Answers
+ 1
it depends in the value of the variable 'i' and the values in 'a'.
28th Jun 2018, 12:02 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
convert a positive integer to negative thanx
28th Jun 2018, 12:17 PM
ayushi lahariya
ayushi lahariya - avatar
0
lets say a= {2,3,4} and value of i is 0
28th Jun 2018, 12:05 PM
ayushi lahariya
ayushi lahariya - avatar
0
my question is it assigning the value but it is calculating it as well not getting exactly what is happening
28th Jun 2018, 12:06 PM
ayushi lahariya
ayushi lahariya - avatar
0
Here is the code and some explanation: https://code.sololearn.com/WUpYUUDOa26G/?ref=app
28th Jun 2018, 12:16 PM
Ulisses Cruz
Ulisses Cruz - avatar