0

i want to write a program using "for" loop, that will generate the following output.

value of a is 0, value of b is 2
value of a is 0, value of b is 4
value of a is 0, value of b is 6
value of a is 1, value of b is 2
value of a is 1, value of b is 4
value of a is 1, value of b is 6
value of a is 2, value of b is 2
value of a is 2, value of b is 4
value of a is 2, value of b is 6

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by WaltP
0
for (i=0;i<3;i++)
{
      for (j=2;j<8;j=j+2)
          {
                printf("value of a is %d, value of b is %d",i,j);
           }
 }

Edited by anup375: n/a

Comments
Do NOT do homework for others. Help them figure it out for themselves.
0
for (i=0;i<3;i++)
{
      for (j=2;j<8;j=j+2)
          {
                printf("value of a is %d, value of b is %d",i,j);
           }
 }

Gee, I thought the OP said

i want to write a program using "for" loop

You just screwed him over.

0

thanks it is working fine...but i when i change
from
for (j=2;j<8;j=j+2)
to
for (j=2;j<8;j=j++)
it is giving inifinite output,,,? why is this happening so ?

and what change should we made to get this output...?

value of a is 0, value of b is 2
value of a is 1, value of b is 4
value of a is 2, value of b is 6


please don't just write the code, provide some instructions too..!

Edited by Xufyan: n/a

0

Because you don't do your own homework. Or maybe it is because j++ already increments the variable j so storing that result into the variable j is redundant. Take your pick.

edit:

Oh, goodie. I just learned after reading your other thread that WaltP just told you the exact same advice I gave you about using j = j++ and similar statements.

Edited by BestJewSinceJC: n/a

0

for (j=2;j<8;j=j++)

Changing the variable from a to j does not change the fact the statement j=j++ is undefined.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.