- 2
Why they is no odd no. Output when x=x+2,when x<10 (increment)
How&why
3 ответов
+ 4
If you start with
X = 1
Then (x = x + 2) = 3, 5, 7, 9
Or do you mean something else?
+ 1
Are you asking why an odd number doesn't print when x = x +2?
This loop that you're describing, if you start x as an odd number, adding 2 to it will always result in an odd number. If you start x as an even number, it will always be even.
If x = 1 in your loop,
X = 1 + 2 (3)
X = 3 + 2 (5)
X = 5 + 2 (7)
X = 7 + 2 (9)
X = 9 +2 (11)
The loop is broken since x is not less than 10 now.
If you start x at 0 or 2,
X = 0 + 2 (2)
X = 2 + 2 (4)
X = 4 + 2 (6)
X = 6 + 2 (8)
X = 8 + 2 (10)
Now that x is no longer less than 10, the loop will be broken
0
No, x=x+2 where int x,x<=10
X at 0, x =0+2=2,
X at 1,x=1+2=3←
why not this