-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (54 loc) · 1.77 KB
/
Program.cs
File metadata and controls
62 lines (54 loc) · 1.77 KB
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
using System.Diagnostics.Metrics;
internal class Program
{
private static void Main(string[] args)
{
int count = 0;
Console.WriteLine("Enter the size of the matrix Line,Column:");
string[] line = Console.ReadLine().Split(" ");
int l = int.Parse(line[0]);
int c = int.Parse(line[1]);
int[,] mat = new int[l, c];
Console.WriteLine("Enter the values of the matrix:");
for (int i = 0; i < l; i++)
{
string[] values = Console.ReadLine().Split(" ");
for (int j = 0; j < c; j++)
{
mat[i, j] = int.Parse(values[j]);
if (mat[i, j] < 0)
{
count++;
}
}
}
Console.WriteLine("Main Diagonal:");
for (int i = 0; i < l; i++)
{
Console.WriteLine(mat[i, i] + " ");
}
Console.WriteLine();
Console.WriteLine("Negative numbers: " + count);
Console.WriteLine('\n' + "Enter the main number of your matrix");
int x = int.Parse(Console.ReadLine());
for (int i = 0; i < l; i++)
{
for (int j = 0; j < c; j++)
{
if (mat[i, j] == x)
{
Console.WriteLine("Position " + i + ", " + j + ":");
if (j > 0)
Console.WriteLine("Left: " + mat[i, j - 1]);
if (i > 0)
Console.WriteLine("Up: " + mat[i - 1, j]);
if (j < c - 1)
Console.WriteLine("Right: " + mat[i, j + 1]);
if (i < l - 1)
Console.WriteLine("Down: " + mat[i + 1, j]);
}
}
}
}
}