-
Notifications
You must be signed in to change notification settings - Fork 0
/
find the number sum of the column in Matrix.txt
144 lines (111 loc) · 2.98 KB
/
find the number sum of the column in Matrix.txt
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// find the number sum of the column in Matrix
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace column_sum_in_matrix
{
internal class Program
{
static void Main(string[] args)
{
//int[,] ar = { { 1, 2, 3 }, { 2, 4, 6 }, { 6, 7, 8 } };
//int i = 0;
//int j;
//while (i < 3)
//{
// j = 0;
// while (j < 3)
// {
// Console.Write(ar[i, j] + " ");
// Console.Write("Enter {0}", (j + 1));
// j++;
// }
// i++;
// Console.WriteLine();
//}
Console.WriteLine("Enter the base array size: ");
int Row = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the child Array size: ");
int Col = int.Parse(Console.ReadLine());
int[,] ar = new int[Row, Col];
int i = 0;
int j;
while (i < Row)
{
j = 0;
while (j < Col)
{
Console.Write("Enter the{0}:- ", (j + 1));
ar[i, j] = int.Parse(Console.ReadLine());
j++;
}
i++;
Console.WriteLine();
}
int ctr = 0;
int ptr;
while (ctr < Row)
{
ptr = 0;
while (ptr < Col)
{
Console.Write(" " + ar[ctr, ptr]);
ptr++;
}
ctr++;
Console.WriteLine();
}
// Console.ReadLine();
Console.WriteLine();
int csum;
// int k = 0;
for (int k = 0; k < Col; k++)
{
csum = 0;
//j = 0;
for (int l = 0; l <Row; l++)
{
Console.WriteLine("sum" + (l + 1) + "Element:" + csum);
csum = csum + ar[l,k];
}
Console.WriteLine();
Console.ReadLine();
}
}
}
}
/* output:
* Enter the base array size:
4
Enter the child Array size:
3
Enter the1:- 1
Enter the1:- 7
Enter the1:- 9
Enter the2:- 0
Enter the2:- 6
Enter the2:- 5
Enter the3:- 6
Enter the3:- 8
Enter the3:- 6
Enter the4:- 8
Enter the4:- 7
Enter the4:- 5
1 7 9
0 6 5
6 8 6
8 7 5
sum1Element:0
sum2Element:1
sum3Element:8
sum1Element:0
sum2Element:0
sum3Element:6
sum1Element:0
sum2Element:6
sum3Element:14
sum1Element:0
sum2Element:8
sum3Element:15*/