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)