Advertisement
A4L

Chapter - 12 - Looping

A4L
Dec 7th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Chapter___12___Looping
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /*
  14.                 **********
  15.                 **********
  16.                 **********
  17.                 **********
  18.                 **********
  19.              */
  20.             for (int row = 0; row < 5; row++) // loops 5 times.. once for each row
  21.             {
  22.                 for (int col = 0; col < 10; col++) // loops 10 times, once for each * on each row.
  23.                 {
  24.                     Console.Write("*");
  25.                 }
  26.                 Console.WriteLine();
  27.             }
  28.             /*
  29.                 *
  30.                 **
  31.                 ***
  32.                 ****
  33.                 *****
  34.                 ******
  35.                 *******
  36.                 ********
  37.                 *********
  38.                 **********
  39.             */
  40.             Console.WriteLine();
  41.             for (int row = 0; row < 10; row++) // Loop 10 times for 10 rows.
  42.             {
  43.                 for (int col = 0; col <= row; col++) // draw a star in each row. Using the row number to deterring the loop count to draw that many stars
  44.                 {
  45.                     Console.Write("*");
  46.                 }
  47.                 Console.WriteLine();
  48.             }
  49.             /*
  50.                 *       4
  51.                ***      3
  52.               *****     2
  53.              *******    1
  54.             *********   0
  55.             */
  56.             //Console.WriteLine();
  57.             for (int row = 0; row < 10; row++) // Loop 10 times for 10 rows.
  58.             {
  59.                 for (int col = 10; col >= row; col--) // draw a pace in each row. Using the row number to deterring the loop count to draw that many space, but reversed. So row 1 draws 10.
  60.                 {
  61.                     Console.Write(" ");
  62.                 }
  63.                 for (int str = 1; str < row*2; str++) // now draw stars after the spaces, use the row count as the star count, but doubled to get pyrimd.
  64.                 {
  65.                     Console.Write("*");
  66.                 }
  67.                 Console.WriteLine();
  68.             }
  69.  
  70.             Console.ReadLine();
  71.         } // End of Main{}
  72.  
  73.        
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement