C#: Display alphabet pattern like K with an asterisk
Write a C# Sharp program to display an alphabet pattern like K with an asterisk.
Visual Presentation:
Sample Solution:
C# Sharp Code:
using System; // Importing necessary namespace
public class Exercise68 // Declaration of the Exercise68 class
{
public static void Main() // Main method, entry point of the program
{
int row, column, j = 5, i = 0; // Declaring variables for rows, columns, j, and i
// Display a message about the pattern being created
Console.Write("\n\n");
Console.Write("Display the pattern like 'K' with an asterisk:\n");
Console.Write("---------------------------------------------");
Console.Write("\n\n");
// Loop for iterating through rows
for (row = 0; row <= 6; row++)
{
// Loop for iterating through columns
for (column = 0; column <= 6; column++)
{
// Check conditions to print '*' or ' ' for specific positions
if (column == 1 || ((row == column + 1) && column != 0))
{
Console.Write("*"); // Print '*' for specific conditions
}
else if (row == i && column == j)
{
Console.Write("*"); // Print '*' for specific conditions
i = i + 1; // Increment i
j = j - 1; // Decrement j
}
else
{
Console.Write(" "); // Print ' ' for other positions
}
}
Console.Write("\n"); // Move to the next line after each row is printed
}
Console.Write("\n"); // Add an extra line at the end for better readability
}
}
Sample Output:
Display the pattern like 'K' with an asterisk: --------------------------------------------- * * * * * * ** * * * * * *
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C#Sharp program to display alphabet pattern like 'J' with an asterisk.
Next: Write a C#Sharp program to display alphabet pattern like 'L' with an asterisk.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics