Advertisement
emzone

Homework AdvancedTopics, Problem 7 - Matrix of Palindromes

Apr 7th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. /* Problem 7.   Matrix of Palindromes
  2. Write a program to generate the following matrix of palindromes of 3 letters with r rows and c columns:
  3. Input   Output
  4. 3 6     aaa aba aca ada aea afa
  5.         bbb bcb bdb beb bfb bgb
  6.         ccc cec cdc cfc cgc chc */
  7.  
  8. using System;
  9.  
  10. class Program
  11. {
  12.     static void Main()
  13.     {
  14.         while (true)
  15.         {
  16.             string input = Console.ReadLine();
  17.             string[] inputArray = input.Split(' ');
  18.             int r = int.Parse(inputArray[0]);
  19.             int c = int.Parse(inputArray[1]);
  20.             string[,] matrix = new string[r, c];
  21.  
  22.             for (int row = 0; row < r; row++)
  23.             {
  24.                 for (int col = 0; col < c; col++)
  25.                 {
  26.                     matrix[row, col] = "" + (char)('a' + row) + (char)('a' + row + col) + (char)('a' + row);
  27.                 }
  28.             }
  29.             for (int row = 0; row < r; row++)
  30.             {
  31.                 for (int col = 0; col < c; col++)
  32.                 {
  33.                     Console.Write(matrix[row, col] + " ");
  34.                 }
  35.                 Console.WriteLine();
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement