Monday, August 2, 2010

Example of C++ For Loop

Counting from 1 to 5

Codes:
#include
#include

void main ()
{
clrscr();

int x,y=0; <-- I assign the value 0 to y to initialize.

For(x=1;x<=5;x++) <-- This funtion is the for loop. It varies or counts the loop 1-5.
{
y = y++;
Printf("y");
}
getch();
}

Output:
1 2 3 4 5

No comments:

Post a Comment