C#x=4,y=9,x=(y%x!=0)? Y/x:y???? | Sololearn: Learn to code for FREE!
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????

23rd Nov 2016, 2:52 AM
Kowsalya A
Kowsalya A - avatar
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 ;)
23rd Nov 2016, 5:00 PM
Margarit
Margarit - avatar
+ 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
19th Mar 2021, 1:07 AM
Marlyn Matematico
Marlyn Matematico - avatar
- 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.
23rd Nov 2016, 3:20 AM
Juan Carlos Luna Hernandez
Juan Carlos Luna Hernandez - avatar