int main()
{
int i ;
clrscr();
for(i = 0; i <= 6; i++) {
if(i % 2 == 0) {
**textcolor(2);**
cprintf("%d\n", i);
}
if(i % 2 != 0) {
**textcolor(3);**
cprintf("%d\n", i);
}
}
getch();
}
OUTPUT:(all evens are in green and odds in blue)
0
1
2
3
4
5
6
Probably \n
is used literally and only does a line feed (= jump to next line and keep cursor at same column) and no carriage return (= put cursor at start of line). Change the \n
s inside the calls to cprintf
to \r\n
.