3.23.2009

the FOR STATEMENT (C++)

NOTE: All letters included in each syntax are VARIABLES. These can be replaced with any other letter in the alphabet. :) VALUES included in the variables (i.e. n=4) could be replaced by any other constant that would satisfy the intsructions. The ASTERISK (*) could also be replaced by any other symbol or letter or number you prefer. It depends on how the structure of your program will be. I just used 4 for the uniformity of the different syntax.


*
**
***
****

SYNTAX:

#include
void main ()

{
int i, n=4, j;

for (i=1; i<=n; i++)
{
for (j=1; j<=i; j++)
{
cout<<"*";
}
cout<< }
}

---------------------------

****
***
**
*


SYNTAX:

#include
void main ()

{
int i, n=4, j;

for (i=1; i<=n; ++i)
{
for (j=4; j>=i; j--)
{
cout<<"*";
}
cout< }
}


---------------------------

*
**
***
****


SYNTAX:

#include
void main ()

{
int a=1, i, d, m;

for (d=4; d>=a; d--)
{
for (i=1; i<=d; i++)
{
cout<<" ";
}

for (m=4; m>=d; m--)
{
cout<<"*";
}
cout< }
}

---------------------------

****
***
**
*


SYNTAX:

#include
void main ()
{
int a=1, i, d, m;

for (d=5; d>=a; d--)
{
for (m=5; m>=d; m--)
{
cout<<" ";
}

for (i=1; i<=d; i++)
{
cout<<"*";
}
cout< }
}

---------------------------

-- was this helpful?
comment me. love to hear it from you. :]
if this is not what you need, i might just help you.
a comment will do. and if i could have the syntax correct and running,
without a doubt, i'll post it. Ü
ciao! :3

**claiire**

No comments: