New course! Every coder should learn Generative AI!
Try a free lesson+ 2
C#x=4,y=9,x=(y%x!=0)? Y/x:y????
3 Answers
+ 6
Juan I think you have made a mistake in the end. That is the condition y% x!=0 is true so we choos the first value which is 9/4 and x=2 in the end. However all in all it was a very great explanation ;)
+ 2
int x=4
int y=9
x = (y % x != 0) ? y/x : y
solution
x = (9%4 != 0) ? 9/4 : 9
x = (1 != 0) ? 9/4 : 9
x = (true) ? 9/4 : 9
x = 9/4
x = 2.1
since x is an int, therefore
x = 2
- 2
You must take and calculate (y % X != 0)
Now replace variables by values (9 % 4 != 0)
Take 9 % 4 and follow:
How many times 4 fit in 9? R= 2
Then 4 * 2 = 8
Now subtract 8 to 9, so you get 1; replace in the formula
(1 != 0) <-- this will return a false
Now replace the result in the full formula
x = (y % x != 0) ? y/x : y
x = false ? y/x : y
Next, replace variables with values
x = false ? 9/4 : 9
considering the structure --> (condition ? action for true : action for false) our condition is false, so we must get the action for false, then the final formula is:
x = 9
I hope i can helped you with this.