C# program to print below alphabet pattern by entering no of lines
abcd
efgh
ijhl
mnop
The pattern you mentioned appears to be an alphabet pattern with a fixed sequence of letters per line. If you want to print this pattern based on the number of lines entered by the user, you can use the following C# program:
using System;
class Program
{
static void Main()
{
Console.Write("Enter the number of lines: ");
int numOfLines = int.Parse(Console.ReadLine());
PrintAlphabetPattern(numOfLines);
}
static void PrintAlphabetPattern(int numOfLines)
{
char currentChar = 'a';
for (int i = 1; i <= numOfLines; i++)
{
for (int j = 1; j <= 4; j++)
{
Console.Write(currentChar);
currentChar++;
if (currentChar > 'z')
{
currentChar = 'a';
}
}
Console.WriteLine();
}
}
}
Below is the output of the above program:
In this program, the PrintAlphabetPattern method takes the number of lines as a parameter and uses nested loops to print the desired alphabet pattern. The outer loop is responsible for iterating through each line, and the inner loop prints the letters 'a' to 'd' on each line. The currentChar variable keeps track of the current letter to be printed, and it wraps back to 'a' after reaching 'z' to maintain the pattern.
When you run the program, it will ask you to enter the number of lines, and then it will print the alphabet pattern accordingly.