using System;
using System.Collections.Generic;
using System.Text;
namespace matrix_row_col_diag_sum
{
class mat
{
int i, j, m, n;
int[,] a = new int[20,20];
int[,] b = new int[20,20];
int[,] c = new int[20,20];
public void get()
{
Console.WriteLine("MATRIX ROW SUM,COLUMN SUM,DIAGONAL SUM");
Console.WriteLine("**************************************");
Console.WriteLine("Enter Row Value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Column Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Elements one by one");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Given Matrix");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
Console.Write("\t{0}",a[i, j]);
}
Console.WriteLine();
}
}
public void row()
{
int r;
for (i = 1; i <= m; i++)
{
r = 0;
for (j = 1; j <= n; j++)
{
r = r + a[i, j];
}
Console.WriteLine("{0} Row Sum={1}", i, r);
}
}
public void col()
{
int c;
for (i = 1; i <= n; i++)
{
c = 0;
for (j = 1; j <= m; j++)
{
c = c + a[j, i];
}
Console.WriteLine("{0} col Sum={1}", i, c);
}
}
public void diag()
{
int d;
d = 0;
if (m == n)
{
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
if (i == j)
{
d = d + a[i, j];
}
}
}
Console.WriteLine("Diagonal Sum= {0}", d);
}
else
{
Console.WriteLine("Can't Perform Diagonal Sum");
}
}
}
class matsum
{
static void Main(string[] args)
{
mat q = new mat();
q.get();
q.row();
q.col();
q.diag();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace matrix_row_col_diag_sum
{
class mat
{
int i, j, m, n;
int[,] a = new int[20,20];
int[,] b = new int[20,20];
int[,] c = new int[20,20];
public void get()
{
Console.WriteLine("MATRIX ROW SUM,COLUMN SUM,DIAGONAL SUM");
Console.WriteLine("**************************************");
Console.WriteLine("Enter Row Value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Column Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Elements one by one");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Given Matrix");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
Console.Write("\t{0}",a[i, j]);
}
Console.WriteLine();
}
}
public void row()
{
int r;
for (i = 1; i <= m; i++)
{
r = 0;
for (j = 1; j <= n; j++)
{
r = r + a[i, j];
}
Console.WriteLine("{0} Row Sum={1}", i, r);
}
}
public void col()
{
int c;
for (i = 1; i <= n; i++)
{
c = 0;
for (j = 1; j <= m; j++)
{
c = c + a[j, i];
}
Console.WriteLine("{0} col Sum={1}", i, c);
}
}
public void diag()
{
int d;
d = 0;
if (m == n)
{
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
if (i == j)
{
d = d + a[i, j];
}
}
}
Console.WriteLine("Diagonal Sum= {0}", d);
}
else
{
Console.WriteLine("Can't Perform Diagonal Sum");
}
}
}
class matsum
{
static void Main(string[] args)
{
mat q = new mat();
q.get();
q.row();
q.col();
q.diag();
}
}
}
No comments:
Post a Comment