Question: Program to print the following Star Pattern.
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Code Snippet:
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Code Snippet:
- using System;
- public class Pattern
- {
- public static void Main()
- {
- int row,col,n,temp,count;
- Console.Write("Enter the no. of row: ");
- n=Convert.ToInt32(Console.ReadLine());
- temp=n;
- count=n;
- for(row = 1; row<=n; row++)
- {
- for(col=1; col<row; col++)
- Console.Write(" ");
- for(col=temp; col>=1; col--)
- Console.Write("* ");
- for(col = temp-1; col>=1; col--)
- Console.Write("* ");
- temp--;
- Console.WriteLine();
- }
- for(row=2; row<=n; row++)
- {
- for(col=1; col<count-1; col++)
- Console.Write(" ");
- for(col=1; col<=row; col++)
- Console.Write("* ");
- for(col=1; col<row; col++)
- Console.Write("* ");
- count--;
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of output |