2017-2-24 nesting of C # base for loops

Source: Internet
Author: User

Use a few exercises to demonstrate the nesting of the For loop

1. Print to form



¡ï ★
★★★★
★★★★★

namespaceNesting of _2017_2_24_for loops {classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter a number:"); intA=Convert.ToInt32 (Console.ReadLine ());  for(inti =1; I <= a;i++ )            {                 for(intb =1; b <= i;b++) {Console.Write ("★"); } console.write ("\ n");        } console.readline (); }    }}

★★★★★
★★★★
¡ï ★

namespace_2017_2_24_for Loops of nested _ painted stars 2{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter a number"); intA =Convert.ToInt32 (Console.ReadLine ());  for(intb =1; b <= a;b++ )            {                 for(intc =a; C >= b;c--) {Console.Write ("★"); } console.write ("\ n");        } console.readline (); }    }}

0000★
000★★
00★★★
0★★★★
★★★★★

namespace_2017_2_24_for loop nesting __ stars 3{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter a number"); intCount =Convert.ToInt32 (Console.ReadLine ()); String b="  "; String C ="※";  for(intD =1; D <= Count; d++)                {                     for(intE = count-1; e >= D; e--) {Console.Write (b);                    } console.write (c);  for(intx =0; X < D1; X + +) {Console.Write (c); } console.write ("\ n");        } console.readline (); }    }}

★★★★★
★★★★
¡ï ★

namespace_2017_2_24_for_ Loop _ nesting __ stars 4{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter a number:"); intA=Convert.ToInt32 (Console.ReadLine ()); String b="  "; String c="☆";  for(intD =1; D <= A; d++)            {                                for(intE =1; E < d;e++) {Console.Write (b); }                 for(intf = a-d; F <= a&&f>=0; f--) {Console.Write (c); } console.write ("\ n");        } console.readline (); }    }}



¡ï ★
★★★★★
★★★★★★★
★★★★★★★★★
★★★★★★★
★★★★★
¡ï ★

namespace_2017_2_24__for loop nested ___ Print Diamond {classProgram {Static voidMain (string[] args) {Console.Write ("Please enter a number:"); intA =Convert.ToInt32 (Console.ReadLine ()); String b="0"; String c="★";  for(intD =1; D <= a;d++ )            {                 for(intE = A-1; e >= D; e--) {Console.Write (b); }                 for(intf =1; F <= (d *2-1); f++) {Console.Write (c); } console.write ("\ n"); }             for(intg =1; G < a;g++ )            {                 for(inth =1; H <= g;h++) {Console.Write (b); }                 for(inti =1; I <= ((a-g) *2-1); i++) {Console.Write (c); } console.write ('\ n');        } console.readline (); }    }}

2017-2-24 nesting of C # base for loops

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.