Home > Back-end >  Want to output a diamond, why not
Want to output a diamond, why not

Time:11-28

CodePudding user response:

 
Void StarTriangle (void)
{
Int nCount=0;
Scanf_s (" % d ", & amp; NCount);

Int I=1;
Int inc=1;
While (I & gt;
=1){
Int nSubCount=nCount - I;
for (int j=0; J & lt; NSubCount; + + j)
{
Printf (" ");
}

NSubCount=I * 2-1;
for (int j=0; J & lt; NSubCount; + + j)
{
Printf (" * ");
}

printf("\r\n");

If (I & gt;=nCount)
Inc=- inc.

I +=inc.
}
}

Void StarTriangle2 (void)
{
Char input=0;
Scanf_s (" % c ", & amp; Input, sizeof (char));

If (input & lt; 'A' | | 'Z' & lt; Input)
{
Printf (" input error \ r \ n ");
return;
}

Int nCount=input - 'A' + 1;

Int I=1;
Int inc=1;
While (I & gt;
=1){
Int nSubCount=nCount - I;
for (int j=0; J & lt; NSubCount; + + j)
{
Printf (" ");
}

NSubCount=I * 2-1;
for (int j=0; J & lt; NSubCount; + + j)
{
Int the add=j;
If (j & gt;=I)
The add=nSubCount - j - 1;
Printf (" % C ", 'A' + add);
}

printf("\r\n");

If (I & gt;=nCount)
Inc=- inc.

I +=inc.
}
}

CodePudding user response:

5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

D
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
Please press any key to continue...

CodePudding user response:

refer to the second floor Minikinfish response:
5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

D
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
Please press any key to continue...

So I have the wrong?
  • Related