Home »
.Net »
C# Programs
C# program to print upper and lower diamond of asterisks till N rows
Here, we are going to learn how to write a C# program that will print upper and lower diamond pattern till N rows?
Submitted by IncludeHelp, on March 26, 2018
Read N (Total number of rows) and print the upper, lower diamond pattern of asterisks in C#.
Pattern -1
*
* *
* * *
* * * *
* * * * *
----- till n rows
Program
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
int inner = 0;
int outer = 0;
int space = 0;
int n = 0;
Console.Write("Enter value of n: ");
n = int.Parse(Console.ReadLine());
for (outer = 1; outer <= n; outer++)
{
for (space =n; space>outer; space--)
{
Console.Write(" ");
}
for (inner = 1; inner <=outer; inner++)
{
Console.Write("* ");
}
Console.WriteLine();
}
}
}
}
Pattern -2
* * * * *
* * * *
* * *
* *
*
----- till n rows.
Program
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
int inner = 0;
int outer = 0;
int space = 0;
int n = 0;
Console.Write("Enter value of n: ");
n = int.Parse(Console.ReadLine());
for (outer = 1; outer <= n; outer++)
{
for (space = 1; space < outer; space++)
{
Console.Write(" ");
}
for (inner = outer; inner <= n; inner++)
{
Console.Write("* ");
}
Console.WriteLine();
}
}
}
}
C# Pattern Printing Programs »