using System namespace FirstLab class FirstLab static void Main string

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
namespace FirstLab
{
class FirstLab
{
static void Main(string[] args)
{
//JaggedArray is an array of arrays
int[][] OrigJaggedArr =
{
new int [] { 1, 1, 0, 1 },
new int [] { 0, 1, 1, 1 },
new int [] { 1, 1, 1, 0 },
new int [] { 1, 0, 1, 1 }
};
Console.WriteLine("Original Array is:\n");
Print_Array(ref OrigJaggedArr);
RowSwap(ref OrigJaggedArr);
Console.WriteLine("\n-------------------\n\nFixed Array is:\n");
Print_Array(ref OrigJaggedArr);
Console.ReadKey();
}
//Method to swap the rows
private static void RowSwap(ref int[][] OrigArr)
{
int[] Temp = new int[4];
int Counter = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
if (OrigArr[i][j] == 0)
{
for (int k = 0; k < 4; k++)
Temp[k] = OrigArr[i][k];
for (int k = 0; k < 4; k++)
if (Temp[k] == 0)
Counter++;
if (Counter > 1)
Environment.Exit(0);
for (int k = 0; k < 4; k++)
{
OrigArr[i][k] = OrigArr[j][k];
OrigArr[j][k] = Temp[k];
}
Counter = 0;
}
// MoreSwap(OrigArr, i, j);
}
}
//One more method to swap the rows
/* private static void MoreSwap(int[][] OrigArr, int Row, int Col)
{
int[] Temp = new int[4];
int Counter = 0;
for (int i = 0; i < 4; i++)
Temp[i] = OrigArr[Row][i];
for (int i = 0; i < 4; i++)
if (Temp[i] == 0)
Counter++;
if (Counter > 1)
Environment.Exit(0);
for (int i = 0; i < 4; i++)
{
OrigArr[Row][i] = OrigArr[Col][i];
OrigArr[Col][i] = Temp[i];
}
}*/
//Method to print the array
private static void Print_Array(ref int[][] Array)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
Console.Write(Array[i][j] + " ");
}
Console.WriteLine();
}
}
}
}