2
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
halex
  • 16,253
  • 5
  • 58
  • 67
Udit Bhardwaj
  • 1,761
  • 1
  • 19
  • 29
  • As a member for over one month you should have had time to read lots of questions, and see how they are formatted. In the future please refrain from putting the question in the title only and just have some code and/or output in the body of the question without any description of your problem. – Some programmer dude Oct 10 '12 at 14:01

2 Answers2

1

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 \ns inside the calls to cprintf to \r\n.

halex
  • 16,253
  • 5
  • 58
  • 67
1

Newlines in Windows is "\r\n". Apparently the cprintf doesn't translate '\n' into the correct sequence so all you are doing is going to the next line with the line feed but you do not put the "cursor" at the beginning if the line with '\r' (carriage return).

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621