- On
- By
- 0 Comment
- Categories: for loop, pyramid triangle
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
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