C# arithmetic operators quiz
@csharp_1001_notes static void Main(string[] args)
{
int a, b, c, x;
a = 90;
b = 15;
c = 3;
x = a - b / 3 + c * 2 - 1;
Console.WriteLine(x);
Console.ReadLine();
}
Что будет выведено на экран?
a) 92
b) 89
c) 90
d) 88
Ответ: в конце страницы ;)
.
.
.
.
.
.
.
.
.
.
.
.
.
Правильный ответ: 90.
И вот как он будет получен:
step 1 : x = 90 - 15 / 3 + 3 * 2 - 1 (15 / 3 evaluated) step 2 : x = 90 - 5 + 3 * 2 - 1 step 3 : x = 90 - 5 + 3 * 2 -1 (3 * 2 is evaluated) step 4 : x = 90 - 5 + 6 - 1 step 5 : x = 85 + 6 - 1 (90 - 5 is evaluated) step 6 : x = 91 - 1( 85 + 6 is evaluated ) step 7 : x = 90(91 - 1 is evaluated)