C# - Loops to build pattern of numbers and *
I have given here the sample code to build the pattern of numbers and * using simple loops
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for(int i = n; i > 1; i--)
{
for(int j = 1; j <= i; j++)
Console.Write("*");
Console.WriteLine();
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
Console.Write("*");
Console.WriteLine();
}
Console.WriteLine();
for(int i = 1; i < n; i++)
{
for(int j = 1; j <= i; j++)
Console.Write(j.ToString());
Console.WriteLine();
}
for(int i = n; i >= 0; i--)
{
for(int j = 1; j <= i; j++)
Console.Write(j.ToString());
Console.WriteLine();
}
Console.WriteLine();
}
}
}
Output
Enter a number: 5
*****
****
***
**
*
**
***
****
*****
1
12
123
1234
12345
1234
123
12
1
|