# Diamond

how can I create a diamond shape using a "for" loop?
It should look like this (it should be a size of 9):

*
***
*****
*******
*********
*******
*****
***
*

The faster I get the responce, the greater pts. u get
LVL 3
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
Edited text of question
0
Author Commented:
Edited text of question
0
Author Commented:
Edited text of question
0
Commented:
int main()
{
int i, j;
const int SIZE=9;  // make sure SIZE is odd
int k = SIZE / 2;

for (int i=1; i <= SIZE; i++) {
for (j = 0; j < k-i+1; j++) cout << " ";
for (j = 0; j < i; j++) cout << "*";
for (j = 0; j < k-i+1; j++) cout << " ";
cout << endl;
}
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
I know this addition is kind of late, but I FINALY got time to update this question.  The answer proposed was NOT correct.  Here is the correct code, albeit in java:

public class Diamond
{

public static void main(String [] args)
{
boolean outer=true;
int line, star, space;
int SIZE=4;

//UPPER PART
for (line = 1; line <= SIZE; line ++)
{
for (star = 0;star < line;star ++)
{     if(outer)
{
for(space = SIZE - line;space >= 0;space --)
{     System.out.print(" ");
outer = false;
}
}
else
{     System.out.print(" ");
}
System.out.print("*");
}

System.out.println();
outer = true;
}

//LOWER PART

for (line = SIZE - 1;line > 0;line --)
{
for (star = 0;star < line;star ++)
{     if(outer)
{
for(space = line - 1;space < SIZE;space ++)
{     System.out.print(" ");
outer = false;
}
}
else
{     System.out.print(" ");
}
System.out.print("*");
}

System.out.println();
outer = true;
}
}
}
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.