for loop

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program

In this article, we will discuss the concept of the C# Full Pyramid star pattern program using a for loop.

In this post, we will learn how to write a program in the C# programming language to print the full pyramid star pattern.

To create a full pyramid in C#, you need to print spaces and stars in the appropriate manner so that the stars form the pyramid’s shape.

Here’s a simple program to print a full pyramid pattern based on the number of rows provided.

Program 1

using System;
public class Pyramid_Pattern
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Enter a number for rows");
        int x=int.Parse(Console.ReadLine ());//number of rows
        for(int i=1; i<=x; i++){
             for(int j=1; j<=x-i; j++){
        Console.Write (" ");
             }
        for(int k=1; k<=(i*2-1); k++){
        Console.Write ("*");
        }
        Console.WriteLine ();
    }
    Console.ReadLine ();
}
}

When the above code is executed, it produces the following result

Pyramid pattern program

 

Explanation

  • Outer for loop: Control the number of rows (i varies from 1 to rows).

 

  • First inner for loop: prints spaces (i varies from 1 to row – i) to centre align the stars.

 

  • The second inner for loop: prints stars (k varies from 1 to  2*  i-1) for each row.

 

Similar post

Java program to print star pyramid pattern 

C program to print star pyramid pattern 

C++ program to print star pyramid pattern 

Python program to print star pyramid pattern 

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

Hollow pyramid triangle pattern in C++ language

Rhombus pattern in Java using for loop

Rhombus pattern in C using while loop

Rhombus pattern in C++ using do-while loop

 

 

 

 

Program to count vowels,consonants,words, characters and space in Java
C# inverted full pyramid star pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

1 week ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

2 weeks ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

2 weeks ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

2 months ago