Advertisement
social1986

Untitled

Dec 12th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MATRIX
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int[][] matrix =
  10. {
  11. new int[] {1, 2, 4, 7 },
  12. new int[] {3, 5, 8, 11 },
  13. new int[] {6, 9 , 12, 14 },
  14. new int[] {10, 13 , 15, 16 }
  15. };
  16.  
  17. var temp = -1;
  18.  
  19. for (int i = 0; i < matrix[0].Length; i++)
  20. {
  21. var row = 0;
  22. temp++;
  23. var col = temp;
  24.  
  25. while (true)
  26. {
  27. if (row == 0 && col == 0)
  28. {
  29. Console.Write(matrix[row][col] + " ");
  30. break;
  31. }
  32. Console.Write(matrix[row][col] + " ");
  33.  
  34. col--;
  35. row++;
  36.  
  37. if (row == matrix.Length || col < 0)
  38. {
  39. break;
  40. }
  41. }
  42. }
  43.  
  44. var column = matrix[1].Length - 1;
  45. temp = 1;
  46. var rows = 1;
  47.  
  48. while(true)
  49. {
  50. Console.Write(matrix[rows][column] + " ");
  51.  
  52. if (rows == matrix.Length - 1 && column == matrix[rows].Length - 1)
  53. {
  54. break;
  55. }
  56. column--;
  57.  
  58. if (rows == matrix.Length - 1)
  59. {
  60. rows = temp;
  61. temp++;
  62. column = matrix[1].Length - 1;
  63. }
  64. rows++;
  65. }
  66. Console.WriteLine();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement