Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program to generate the following matrix of palindromes of 3 letters with r rows and c columns.
- namespace _07.MatrixOfPalindromes
- {
- using System;
- public class MatrixOfPalindromes
- {
- public static void Main(string[] args)
- {
- checked
- {
- int countR;
- do
- {
- Console.Write("Enter Count of rows R: ");
- }
- while (!int.TryParse(Console.ReadLine(), out countR) || countR < 1);
- int countC;
- do
- {
- Console.Write("Enter Count of columns C: ");
- }
- while (!int.TryParse(Console.ReadLine(), out countC) || countC < 1);
- char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
- Console.WriteLine("The Matrix of Palindromes is:\n");
- for (int rows = 0; rows < countR; rows++)
- {
- for (int cols = rows; cols < rows + countC; cols++)
- {
- string palindrome = alphabet[rows % alphabet.Length].ToString() + alphabet[cols % alphabet.Length].ToString() + alphabet[rows % alphabet.Length].ToString();
- Console.Write("{0,4}", palindrome);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement