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

C# inverted full pyramid star pattern

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

3 weeks 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…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

8 months ago