Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Matrix representation in C#


This code will ask the user for number of columns and rows.
Then it will result in two dimensional matrix representation.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. try
  13. {
  14. string i;
  15.  
  16. string j;
  17.  
  18. int m;
  19.  
  20. int n;
  21.  
  22. int no_of_rows = 0;
  23.  
  24. int no_of_columns = 0;
  25.  
  26.  
  27.  
  28. Console.WriteLine("Enter the number of rows ");
  29.  
  30. i = Console.ReadLine();
  31.  
  32. no_of_rows = Convert.ToInt32(i);
  33.  
  34.  
  35.  
  36. Console.WriteLine("Enter the number of columns ");
  37.  
  38. j = Console.ReadLine();
  39.  
  40. no_of_columns = Convert.ToInt32(j);
  41.  
  42. for (n = 0; n < no_of_rows; n++)
  43. {
  44. for (m = 0; m < no_of_columns; m++)
  45. {
  46.  
  47. Console.Write(n.ToString()+m.ToString()+" ");
  48.  
  49. }
  50.  
  51. Console.WriteLine(" \n ");
  52.  
  53. }
  54.  
  55. }
  56.  
  57. catch (Exception e)
  58. {
  59.  
  60. Console.WriteLine("Exception occured: " + e.Message);
  61. }
  62. }
  63. }
  64. }
  65.  


  1. Enter the number of rows
  2. 4
  3. Enter the number of columns
  4. 4
  5.  
  6. 00 01 02 03
  7.  
  8. 10 11 12 13
  9.  
  10. 20 21 22 23
  11.  
  12. 30 31 32 33