C# Topics
- C# Intro
- C# String Methods
- C# Interview Programs
- C# Star Pattern
- C# Number Pattern
- C# Alphabet Pattern
- Alphabet Pattern 1
- Alphabet Pattern 2
- Alphabet Pattern 3
- Alphabet Pattern 4
- Alphabet Pattern 5
- Alphabet Pattern 6
- Alphabet Pattern 7
- Alphabet Pattern 8
- Alphabet Pattern 9
- Alphabet Pattern 10
- Alphabet Pattern 11
- Alphabet Pattern 12
- Alphabet Pattern 13
- Alphabet Pattern 14
- Alphabet Pattern 15
- Alphabet Pattern 16
- Alphabet Pattern 17
- Alphabet Pattern 18
- Alphabet Pattern 19
- Alphabet Pattern 20
- Alphabet Pattern 21
- Alphabet Pattern 22
- Alphabet Pattern 23
- Alphabet Pattern 24
- Alphabet Pattern 25
- Alphabet Pattern 26
- Alphabet Pattern 27
- Alphabet Pattern 28
- Alphabet Pattern 29
- Alphabet Pattern 30
- Alphabet Pattern 31
- Alphabet Pattern 32
- Alphabet Pattern 33
- Alphabet Pattern 34
C# Alphabet Pattern 16
Photo Credit to CodeToFun
C# Alphabet Pattern 16
Here`s a program that prints the above alphabet pattern using C# Programming:
using System;
namespace myApp {
class Program {
static void Main(string[] args) {
int i, j;
int k = 0;
char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
for (i = 1; i <= 5; i += 2) {
for (j = 5; j >= 1; j--) {
if (j > i)
Console.Write(" ");
else
Console.Write(alpha[k++] + " ");
}
Console.WriteLine();
}
}
}
}
💻 Testing the Program
When you run the above program, it will print the following output:
A B C D E F G H I
🧠 How the Program Works
Let's break down the logic behind the code:
- The program starts by importing the necessary namespace System, which provides access to the Console class and other system-related functionalities.
- The program defines a class called Program within the namespace myApp.
- Inside the Program class, the Main method is declared, which is the entry point of the program. It takes an array of strings args as input, although it is not used in this program.
- Three variables are declared: i, j, and k. i and j are integers, and k is initialized to 0. These variables will be used for loop control and array indexing.
- An array of characters named alpha is created and initialized with the characters 'A' to 'Z'. This array contains all the uppercase letters of the English alphabet.
- The program enters a for loop with the variable i starting at 1 and incrementing by 2 in each iteration, and it runs as long as i is less than or equal to 5.
- Inside the outer loop, there is another for loop with the variable j starting at 5 and decrementing by 1 in each iteration, running as long as j is greater than or equal to 1.
- In each iteration of the inner loop, the program checks if j is greater than i. If j is greater than i, it means there should be spaces printed, so the program writes a space character to the console using Console.Write(" ").
- If j is not greater than i, it means it's time to print a character from the alpha array. The program writes the character at index k from the alpha array to the console using Console.Write(alpha[k++] +" ").
- After printing the characters or spaces for each row, the program moves to the next line using Console.WriteLine() to start a new row.
- The outer loop continues until i exceeds 5, and the pattern of characters and spaces is printed accordingly.
- Once the outer loop is finished, the Main method completes, and the program execution ends.
💯 Tips for Enhancement:
Explore the versatility of this pattern by adjusting its parameters. Whether you increase or decrease the size, tweak the spacing, or modify the characters used, each change opens up a world of possibilities, allowing you to customize and create your unique visual effects.
✔ Conclusion:
Creating visually appealing patterns is not only a fun endeavour but also a great way to enhance your programming or design skills. We hope this tutorial has inspired you to explore the world of creative coding. Share your creations with us, and let your imagination run wild!
🤗 Closing Call-to-Action:
We'd love to see your unique interpretations of the alphabet pattern. Share your creations in the comments below, and don't hesitate to reach out if you have any questions or suggestions for future tutorials. Happy coding!
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (C# Alphabet Pattern 16) please comment here. I will help you immediately.