how to find the output of the following segment?

Oct 12, 2012 at 7:54am
for (x=1, y=5; x+y<=10; x++)
{
cout <<x<< “ “<<y<<endl;
y++;
}
Oct 12, 2012 at 9:15am
May I know what variable u want to output?

Because u did output for both variables that is in the code
Last edited on Oct 12, 2012 at 9:22am
Oct 12, 2012 at 9:21am
how to find the output of the following segment?


Run the program, and see what the output is.
Oct 12, 2012 at 9:24am
for (x=1; y=5; x+y<=10; x++;y++)
Will result in compile errors. The for loop takes only three portions(or any other suitable word) of statements. Syntax:

for(initialization;condition;increment/decrement);

Also, if you wanna specify more than one statement in the "portions", then use the comma(',') operator.
eg:
for (x=1, y=5; x+y<=10; x++,y++)


@vichu8888
So I took out my suggestion

Yeah no problem!

Aceix.
Last edited on Oct 12, 2012 at 10:42am
Oct 12, 2012 at 9:38am
@Aceix
Is your reply for me?
Because I suggested him the code
for (x=1; y=5; x+y<=10; x++;y++)
But later when I tried in my lappy, I examined the error. So I took out my suggestion.

Sorry for that
Last edited on Oct 12, 2012 at 9:39am
Oct 12, 2012 at 2:51pm
for (x=1, y=5; x+y<=10; x++)
{
cout <<x<< “ “<<y<<endl;
y++;
}

Output:
1 5
2 6
3 7
Oct 12, 2012 at 3:15pm
It's not that hard to work it out in your head.

Both x and y are incremented by 1 at the end of each iteration of the loop. That means (x+y) goes up by 2 each time. Thus (x+y) is 6, 8 10, meaning three passes through the loop. The values of x and y output each time are straightforward.
Oct 13, 2012 at 5:14am
No replies from the OP - could be a typical trolling question?

If not. let's see some feedback / thanks from the OP.
Topic archived. No new replies allowed.