. net_ to print a triangle of the specified number of lines with a console program (interview questions)

Source: Internet
Author: User

Below is a 4-row inverted triangle pattern consisting of an * number. Requirements:

1. Enter the number of rows in the inverted triangle, the number of rows of 3-21, for illegal rows, ask to throw the hint "illegal number of rows!" ”;

2. Print the inverted triangle on the screen that specifies the number of rows.

*******

*****

***

*

 Static voidMain (string[] args) {             while(true)            {                intK =1; Console.WriteLine ("Please enter the number of lines"); intnum =Convert.ToInt32 (Console.ReadLine ());  while(Num <3|| num > +) {Console.WriteLine ("input Error, please enter line number from new"); Num=Convert.ToInt32 (Console.ReadLine ()); }                intnum2 =num;  for(inti = num; i >0; i--)                {                    if(num2 = =i) { for(intj =0; J < i*2-1; J + +) {Console.Write ("*"); } console.write ("\ r \ n"); }                    Else                    {                         for(intj =0; J < K; J + +) {Console.Write (" "); } k++;  for(intD =0; D < i*2-1; d++) {Console.Write ("*"); } console.write ("\ r \ n");        }}} Console.readkey (); }
View Code

. net_ to print a triangle of the specified number of lines with a console program (interview questions)

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.