30 : -2147483648
. 10 , , int. ''7' , , , , 1, , . , 2 . ( . 3.)
. , 127.
= 127; = 127;
?
? #. if-then-else. ? , . .
1? 2: 3;
1 bool, 2 3 . ?.
? . !. , 2, ? . 1 , 3, ?. , absval val.
absval = val < 0? -val: val; // val
absval val, . val , absval , .
?. , .
// , ?.
Using System;
class NoZeroDiv {
static void Main() { int result;
for(int i = -5; i < 6; i++) {
result = i!= 0? 100 / i: 0; if (i! = 0)
Console.WriteLine("100 / " + i + " " + result);
}
}
}
.
100 / -5 -20 100 / -4 -25 100 / -3 -33 100 / -2 -50 100 / -1 -100 100 / 1 100 100 / 2 50 100 / 3 33 100 / 4 25 100 / 5 20
|
|
.
result = i!= 0? 100 / i: 0;
result 100 i. , i . , result , .
? . , , ?, . ? bool,
If. 100 , .
// , .
Using System;
class NoZeroDiv2 { static void Main() {
for(int i = -5; i < 6; i++)
if(i!= 0? (i%2 == 0): false)
Console.WriteLine("100 / " + i + " " + 100 / i);
}
}
if . i , i f . i , if , i , , . . , .
C# , . , , , , .
=10/*(127+); = 10 / * (127 + );
I
, , , . ^ . , , , . , ?
= /3-34*temp+127; = (/3) - (34*temp) + 127;
. 4.2 #: . , .
4.2. C#
[]
.
++
--
Checked