Advertisement
BojidarDosev

Размяна на колони и редове

Oct 11th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp4
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[,] array = new int[4, 4];
  10.             string s;
  11.             int c;
  12.             for (int i = 0; i < 4; i++)
  13.             {
  14.                 for (int j = 0; j < 4; j++)
  15.                     array[i, j] = int.Parse(Console.ReadLine());
  16.             }
  17.             for (int i = 0; i < 4; i++)
  18.             {
  19.                 s = "";
  20.                 for (int j = 0; j < 4; j++)
  21.                 {
  22.                     s += String.Format("{0,4}", array[i, j]);
  23.                 }
  24.                 Console.WriteLine(s);
  25.  
  26.             }
  27.             for (int i = 0; i < 4; i++)
  28.             {
  29.                 c = array[0, i];
  30.                 array[0, i] = array[2, i];
  31.                 array[2, i] = c;
  32.                 c = array[1, i];
  33.                 array[1, i] = array[3, i];
  34.                 array[3, i] = c;
  35.             }
  36.             Console.WriteLine("razmestwane na redowe");
  37.             for (int i = 0; i < 4; i++)
  38.             {
  39.                 s = "";
  40.                 for (int j = 0; j < 4; j++)
  41.                 {
  42.                     s += String.Format("{0,4}", array[i, j]);
  43.                 }
  44.                 Console.WriteLine(s);
  45.             }
  46.             for (int i = 0; i < 4; i++)
  47.             {
  48.                 c = array[i, 0];
  49.                 array[i, 0]= array[i, 2];
  50.                 array[i, 2] = c;
  51.  
  52.                 c = array[i, 1];
  53.                 array[i, 1] = array[i, 3];
  54.                 array[i, 3] = c;
  55.             }
  56.             Console.WriteLine("razmestwane na koloni");
  57.             for (int i = 0; i < 4; i++)
  58.             {
  59.                 s = "";
  60.                 for (int j = 0; j < 4; j++)
  61.                 {
  62.                     s += String.Format("{0,4}", array[i, j]);
  63.                 }
  64.                 Console.WriteLine(s);
  65.             }
  66.         }
  67.     }
  68. }
  69. /*
  70.  16
  71.  3
  72.  2
  73.  13
  74. 5
  75. 10
  76. 11
  77. 8
  78. 9
  79. 6
  80. 7
  81. 12
  82. 4
  83. 15
  84. 14
  85. 1
  86. */
  87. Имате двумерен масив 4x4 от естествени числа от интервала [1..100], чийто стойности са въведени предварително.
  88. Да се състави програма на C++, чрез която се разменят елементите на два реда в масивa.
  89. - в редове 1 и 2 чрез трета променлива;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement