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);
           }
 }
commented: Do NOT do homework for others. Help them figure it out for themselves. -2
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..!

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.