Use the C # language to display Christmas tree images on the Interface

Source: Internet
Author: User

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 );

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.