Today, the instructor assigned a assignment. First, use * to display an equilateral triangle image on the console interface, and then think about how to implement a Christmas tree image. I know that there are code that can be used for reference on the Internet, but I still think about it myself. Haha, I have a sense of accomplishment. So we have to bask in the sun.
The specific code is as follows:
// Equilateral triangle function
Static void triangle (INT high)
{
For (INT I = 0; I {
For (Int J = 0; j <2 * high; j ++)
{
If (j> = (high-I) & J <= (high + I ))
{
Console. Write ("*");
}
Else console. Write ("");
}
Console. writeline ();
}
}
// Christmas tree function
Static void trees (INT high, int width)
{
For (INT I = 0; I {
For (Int J = 0; j <width; j ++)
{
If (j> = (width/2-I) & J <= (width/2 + I ))
{
Console. Write ("*");
}
Else console. Write ("");
}
Console. writeline ();
}
}
// Tree trunk
Static void treesbranch (INT width)
{
For (int K = 0; k <6; k ++)
{
For (int l = 0; L <width; l ++)
{
If (L> = (width/2-1) & L <= (width/2 + 1 ))
{
Console. Write ("*");
}
Else console. Write ("");
}
Console. writeline ();
}
}
Static void main (string [] ARGs)
{
Console. writeline ("Enter the height of the equilateral triangle :");
Int H = convert. toint32 (console. Readline ());
Triangle (h );
// Although the requirement is displayed on the page ~ 4, but I have no judgment in the Code. Even if a large number is input, it can be implemented, but it is too big to look good.
Console. writeline ("Enter the number of Christmas tree layers you need (2 ~ 4) ");
Int A = convert. toint32 (console. Readline ());
Int wth = 2*(3 + );
For (int K = 3; k <3 + A; k ++)
{
Trees (K, WTH );
}
Treesbranch (WTH );
}