stefan1919

Matrix of Palindromes (with array)

Aug 23rd, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int rows = int.Parse(Console.ReadLine());
  14.             int cols = int.Parse(Console.ReadLine());
  15.             char mainCharacter;
  16.             string alphabet1 = "abcdefghijklmnopqrstuvwxyz";
  17.             char[] alphabet = alphabet1.ToArray();
  18.             char helpCharacter;
  19.             string[,] matrix = new string[rows, cols];
  20.             for (int row = 0; row < matrix.GetLength(0); row++)
  21.             {
  22.                 for (int col = 0; col < matrix.GetLength(1); col++)
  23.                 {
  24.                     string output = string.Empty;
  25.                     mainCharacter = alphabet[row];
  26.                     helpCharacter = alphabet[col + row];
  27.                     string outMain = mainCharacter.ToString();
  28.                     string outHelp = helpCharacter.ToString();
  29.                     output += mainCharacter;
  30.                     output += helpCharacter;
  31.                     output += mainCharacter;
  32.                     output += " ";
  33.                     matrix[row, col] = output;
  34.                    
  35.                 }
  36.                
  37.             }
  38.  
  39.             for (int i = 0; i < matrix.GetLength(0); i++)
  40.             {
  41.                 for (int j = 0; j < matrix.GetLength(1); j++)
  42.                 {
  43.                     Console.Write(matrix[i, j]);
  44.                 }
  45.                 Console.WriteLine();
  46.             }
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment