Hello everyone, I just joined this forum. I need some thoughts about a diamond nested for loop, the code below shows 17 stars at middle which is what I need, and one more thing I need is to only print out
1, 4, 9, 13, 17, 13, 9, 4, 1, * pattern. Thanks guys!
Code:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int main()
{ clrscr();
int numStars = 1,
numSpaces = 8;
while (numSpaces > 0)
{
for (int i = 0; i < numSpaces; i++)
{
cout << " ";
}
for ( i = 0; i < numStars; i++)
{
cout << "*";
}
cout << "\n";
numStars += 2;
numSpaces--;
}
while (numStars > 0)
{
for (int i = 0; i < numSpaces; i++)
{
cout << " ";
}
for ( i = 0; i < numStars; i++)
{
cout << "*";
}
cout << "\n";
numStars -= 2;
numSpaces++;
}
getch();
return 0;
}