Hello everyone i am new in C language and need some basic help.
see this program,
void main(void)
{
int a,b;
clrscr ();
{
for (a=1;a<5;a++)
{
for (b=2;b<6;b++)
{
printf ("value of a is %d , value of b is %d \n",a,b);
b=a+1;
a=a++;
}
}
}
getch();
}
i've used 'for' loops in this program and i am getting this output.
value of a is 1, value of b is 2
value of a is 2, value of b is 3
value of a is 3, value of b is 4
value of a is 4, value of b is 5
and it is perfectly fine.
but i want to know that why i need to increment the value of a again since i've already incremented it in this statement
{
for (a=1;a<5;a++)
{
why i need to increment it again after printf function ?
why it is not working if i am not incrementing it again ?
2nd question:
see this program,
void main(void)
{
int a,b;
clrscr ();
a=0, b=2;
while (a<1)
{
while (b<7)
{
printf ("a is %d, b is %d\n",a,b);
b=b+2;
}
a=a+1;
}
getch ();
}
i am getting this output and it is perfectly ok.
a is 0, b is 2
a is 0, b is 4
a is 0, b is 6
but when i am writing a=a+1; after b=b+2;
i.e
void main(void)
{
int a,b;
clrscr ();
a=0, b=2;
while (a<1)
{
while (b<7)
{
printf ("a is %d, b is %d\n",a,b);
b=b+2;
a=a+1;
}
}
getch ();
}
the program is giving different output
a is 0, b is 2
a is 1, b is 4
a is 2, b is 6
why is this happening ??
why the value of a is increasing from 0 when i am writing a=a+1; after b=b+2 ??
why should i have to write a=a+1; after delimeter ?