6.perform Matrix Operations Using Object: System System - Collections.Generic System - Linq System - Text

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

6.

Perform Matrix Operations Using Object

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp12
{
class Matrix
{
public
int row, col;
int[,] a = new int[10, 10];

public void get()


{
int i, j;
Console.WriteLine("Enter the order of the Matrix: ");
row = int.Parse(Console.ReadLine());
col = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the matrix element:");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
}

public void display()


{
Console.WriteLine("Given Matrix :");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
Console.Write(a[i, j] + "\t");
}
Console.WriteLine();
}
}
public void transpose()
{
Console.WriteLine("Transpose Matrix:");
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
Console.Write(a[j, i] + "\t");
}
Console.WriteLine();
}
}
}

class trans
{
public static void Main(string[] args)
{
Matrix m = new Matrix();
m.get();
m.display();
m.transpose();
Console.ReadKey();
}

}
}
Output:
9.Implement Operator Overloading

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace overloading
{
class Calculate
{
public int n1, n2;
public Calculate(int no1, int no2)
{
n1 = no1;
n2 = no2;
}

public static Calculate operator + (Calculate c1,Calculate c2)


{
c1.n1+=c2.n1;
c1.n2+=c2.n2;
return c1;
}
public void print()
{
Console.WriteLine("Number 1: " +n1);
Console.WriteLine("Number 2: " +n2);
}
}
class over
{
static void Main(string[] args)
{
Calculate c = new Calculate(20,-40);
c.print();
Calculate c3 = new Calculate(20, -40);
c3+=c;
c3.print();
Console.ReadKey();
}
}
}
Output:

You might also like