The Program in C# Program to Display Pattern like right angle triangle using Asterisk is given below:
using System;
namespace RightAngleTriangle
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter the number of rows here to create the pattern of right angle triangle: ");
int rows = int.Parse(Console.ReadLine());
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Output:
Hello Codeauri Family, enter the number of rows here to create the pattern of right angle triangle:
9
*
**
***
****
*****
******
*******
********
*********
Pro-Tips💡
Here are the step by step execution of above program:
- The
using System;
directive is a reference to the System namespace, which provides access to commonly used types, such as theConsole
class. - The code defines a namespace
RightAngleTriangle
that contains a single classProgram
. - The
Main
method is the entry point of the program and contains the logic to create the right-angled triangle pattern. Console.WriteLine
is used to display a prompt asking the user to enter the number of rows.- The
int.Parse
method is used to parse the user input from the console and store it as an integer in therows
variable. - The code uses two nested for loops to build the right-angled triangle pattern. The outer loop runs
rows
number of times and the inner loop runsi
number of times, wherei
is the current iteration of the outer loop. - Within the inner loop, the
Console.Write
method is used to print a single asterisk (*) for each iteration. - The
Console.WriteLine
method is used at the end of each iteration of the outer loop to move to the next line. - Finally, the
Console.ReadLine
method is used to prevent the console window from closing immediately after the program execution.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.