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

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 6 Years Ago by anup375: n/a

Comments
Do NOT do homework for others. Help them figure it out for themselves.
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.

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 6 Years Ago by Xufyan: n/a

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 6 Years Ago by BestJewSinceJC: n/a

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.