+ 2
What is the final value of y? //Program #include<iostream> using namespace std; int main() { int y; for(y=2;y<=6;y+=2) cout<<y; }
5 Respostas
+ 4
No, the increment is done at each loop except the first. Besides, if you look at the condition, you know that y has to be greater than 6 for the loop to end.
Here is the equivalent with a while loop:
int y = 2;
while (y <= 6) {
cout << y;
y += 2;
}
+ 2
Okay. So it means that the value which will get printed will be 6, but the final value of y will be 8?
And Thanks!!
+ 1
There is no spoon, I mean, no x.
If you mean y, the program will print 246 and the value of y will be 8 when the for loop ends.
+ 1
That's right.
0
Shouldn't it be 6?? As it will be the last time the loop runs....