Home > Back-end >  The underlying code farmers afraid graphics? Do all questions! - graphic talked about the first peri
The underlying code farmers afraid graphics? Do all questions! - graphic talked about the first peri

Time:10-07

graphics is very annoying, finish see this, what can set!
To see a basic graphics:
Enter a number greater than 2, the output of a hollow diamond,
Input:
3
Output:
*
* *
* *
* *
*
set a for loop? NO!!!!!!
attention! Bright artifact's time:
the problem solving skills: printing, step by step a good domain wide,
On the small 2, code! (of the new, the code is relaxed ) :
 
#include
#include//setw () the header file
using namespace std;
Int n, num;//n is greater than the second number, num is number, n * 2-1
Void the execute (int n)//print function,
{
If (n==1)//special case, special processing,
{
Cout}
The else
{
Coutfor(int i=1; i<=n - 2; I++)//cut turn tail and output space,
{
Cout<" ";
}
Cout<" * "& lt; }
}
Int main ()
{
Cin> & gt; n;
Num=2 * n - 1;//note that output diamond head office number is 2 * n - 1, the middle layer by space also have 2 * n - 1 characters,
for(int i=1; i{
If (I % 2==1) with odd//total number can only in a row,
{
Execute (I);
}
}
For (int I=num - 2; i>=1; I -)//control num line after the number of rows,
{
If (I % 2==1)
{
Execute (I);
}
}
return 0;
//perfect end,
}

Post for the first time, if there is any mistake, forgive me,
  • Related