Basic Programming C# Examples

C# Program to Display Pattern like right angle triangle using Asterisk

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:

  1. The using System; directive is a reference to the System namespace, which provides access to commonly used types, such as the Console class.
  2. The code defines a namespace RightAngleTriangle that contains a single class Program.
  3. The Main method is the entry point of the program and contains the logic to create the right-angled triangle pattern.
  4. Console.WriteLine is used to display a prompt asking the user to enter the number of rows.
  5. The int.Parse method is used to parse the user input from the console and store it as an integer in the rows variable.
  6. 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 runs i number of times, where i is the current iteration of the outer loop.
  7. Within the inner loop, the Console.Write method is used to print a single asterisk (*) for each iteration.
  8. The Console.WriteLine method is used at the end of each iteration of the outer loop to move to the next line.
  9. 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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X