1. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 2 : EX.NO-1 Matrix addition subtraction multiplication
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
class matadd
{
int[,] A = new int[10, 10];
int[,] B = new int[10, 10];
int[,] C = new int[10, 10];
int[,] D = new int[10, 10];
int m, n, i, j;
public void input()
{
Console.WriteLine("Enter the Number of Rows and Columns");
m = Convert.ToInt16(Console.ReadLine());
n = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter the first Matrix value");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
A[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.WriteLine("ENter the Second Matrix value");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
B[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.Clear();
}
public void add()
2. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
{
Console.WriteLine("nMatrix value of A:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(A[i, j] + "t");
}
Console.WriteLine();
}
Console.WriteLine("nMatrix value of B:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(B[i, j] + "t");
}
Console.WriteLine();
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
C[i, j] = A[i, j] + B[i, j];
}
}
Console.WriteLine("nMatrix Addition");
Console.WriteLine("~~~~~~~~~~~~~~~~~");
// Console.WriteLine("The Addition of Two matrix is:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(C[i,j]+"t");
}
Console.WriteLine();
}
}
public void sub()
{
3. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("nMatrix Subtraction");
Console.WriteLine("~~~~~~~~~~~~~~~~~");
/*Console.WriteLine("nMatrix value of A:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(A[i, j] + "t");
}
Console.WriteLine();
}
Console.WriteLine("nMatrix value of B:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(B[i, j] + "t");
}
Console.WriteLine();
}*/
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
C[i, j] = A[i, j] - B[i, j];
}
}
Console.WriteLine("The Subtraction of Two matrix is:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(C[i, j] + "t");
}
Console.WriteLine();
}
}
public void mul()
{
4. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("nMatrix Multiplication");
Console.WriteLine("~~~~~~~~~~~~~~~~~");
Console.WriteLine("nMatrix value of A:");
/*for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(A[i, j] + "t");
}
Console.WriteLine();
}
Console.WriteLine("nMatrix value of B:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(B[i, j] + "t");
}
Console.WriteLine();
}*/
D[i, j] = 1;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
D[i, j] *= A[i, j] + B[i, j];
} }
Console.WriteLine("The Multiplication of Two matrix is:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(D[i, j] + "t") }
Console.WriteLine();
} } }
class matrix
{ static void Main(string[] args)
{ matadd ma = new matadd();
5. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
ma.input();
ma.add();
ma.sub();
ma.mul();
Console.ReadLine(); } } }
Output:Matrix value of A:
1 2
5 2
Matrix value of B:
3 6
8 4
Matrix Addition
~~~~~~~~~~~~~~~~~
4 8
13 6
Matrix Subtraction
~~~~~~~~~~~~~~~~~
The Subtraction of Two matrix is:
-2 -4
-3 -2
Matrix Multiplication
~~~~~~~~~~~~~~~~~
Matrix value of A:The Multiplication of Two matrix is:
0 0
0 0
6. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 2 : EX.NO-2 INVERSION OF MATRIX
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication25
{
class matadd
{
int[,] A = new int[10, 10];
int i, j, m, n;
float determinant = 0;
public void input()
{
Console.WriteLine("Enter the Number of Rows and Columns");
m = Convert.ToInt16(Console.ReadLine());
n = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter the first Matrix value");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
A[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
}
public void add()
{
7. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("nMatrix value of A:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(A[i, j] + "t");
}
Console.WriteLine();
}
for (i = 0; i < 3; i++)
determinant = determinant + (A[0, i] * (A[1, (i + 1) % 3] * A[2, (i + 2) %
3] - A[1, (i + 2) % 3] * A[2, (i + 2) % 3]));
Console.WriteLine("Inverse of matrix is");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write("{0}t", ((A[(i + 1) % 3, (j + 1) % 3] * A[(i + 2) % 3, (j
+ 2) % 3]) - (A[(i + 1) % 3, (j + 2) % 3] * A[(i + 2) % 3, (j + 1) % 3])) /
determinant);
}
Console.WriteLine();
}
}
}
class matrix
{
static void Main(string[] args)
{
int ch;
do
{
Console.WriteLine("Inverse of the Matrix");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
matadd ma = new matadd();
ma.input();
8. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
ma.add();
Console.WriteLine("Do you want to continue Press(1/0)");
ch = int.Parse(Console.ReadLine());
Console.ReadLine();
}
while (ch == 1);
}
}
}
OUTPUT:
9. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 2 : EX.NO-3 REVERSE ORDER
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class rever
{
int[] a = new int[10];
int n;
public void input()
{
Console.WriteLine("Enter the Number of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Values");
for (int i = 0; i < n; i++)
{
Console.Write("Number[{0}]=", i);
a[i] = int.Parse(Console.ReadLine());
}
}
public void rev()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i] > a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
10. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
}
Console.WriteLine("Reverse of Given Number:");
for (int i = 0; i < n; i++)
{
Console.Write("Number[{0}]=",i);
Console.WriteLine(a[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do
{
rever r = new rever();
Console.WriteLine("Reverse of Given Elements");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
r.input();
r.rev();
Console.WriteLine("Do You want to perform again Press(1/0)");
ch = int.Parse(Console.ReadLine());
}
while (ch == 1);
Console.ReadLine();
}
}
}
11. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Output:
Reverse of Given Elements
~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the Number of Elements
5
Enter the Values
Number[0]=2
Number[1]=4
Number[2]=5
Number[3]=1
Number[4]=23
Reverse of Given Number:
Number[0]=23
Number[1]=5
Number[2]=4
Number[3]=2
Number[4]=1
Do You want to perform again Press(1/0)
0
12. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST -2 : EX.NO-4 BIGGEST,LOWESTELEMENTS OF AN ARRAY
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class rever
{
int[] a = new int[10];
int n;
public void input()
{
Console.WriteLine("Enter the Number of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Values");
for (int i = 0; i < n; i++)
{
Console.Write("Number[{0}]=", i);
a[i] = int.Parse(Console.ReadLine());
}
}
public void rev()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i] < a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
13. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("Lower to Higher Order");
for (int i = 0; i < n; i++)
{
Console.Write("Number[{0}]=", i);
Console.WriteLine(a[i]);
}
Console.Write("Smallest Element is");
Console.WriteLine(a[0]);
Console.Write("Largest Element is ");
Console.WriteLine(a[n-1]);
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do
{
rever r = new rever();
Console.WriteLine("Biggest and lowest of Given Elements in array");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
r.input();
r.rev();
Console.WriteLine("Do You want to perform again Press(1/0)");
ch = int.Parse(Console.ReadLine());
}
while (ch == 1);
Console.ReadLine();
}
}
}
14. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Output:
Biggest and lowest of Given Elements in array
~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the Number of Elements
5
Enter the Values
Number[0]=3
Number[1]=56
Number[2]=2
Number[3]=6
Number[4]=3
Lower to Higher Order
Number[0]=2
Number[1]=3
Number[2]=3
Number[3]=6
Number[4]=56
Smallest Element is2
Largest Element is 56
Do You want to perform again Press(1/0)
15. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 2 : EX.NO-5 SWAPPING OF TWO ARRAY
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
classswaping
{
int[] a = newint[10];
int[] b = newint[10];
int[] c = newint[10];
int i, n;
publicvoid input()
{
Console.WriteLine("enter of no of elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("enter first array---->");
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("_______________");
Console.WriteLine("enter second array elements---->");
for (i = 0; i <= n; i++)
{
b[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("_________________");
}
publicvoid display()
{
Console.WriteLine("BEFORE swaPping two arrays");
Console.WriteLine("first array");
for (int i = 0; i < n; i++)
17. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
{
swaping sw = newswaping();
sw.input();
sw.display();
Console.WriteLine("do u wanto conntinue(1) or (0)");
ch = int.Parse(Console.ReadLine());
} while (ch == 1);
}
}
}
Output:
enter of no of elements
4
enter first array---->
5
23
1
67
_______________
enter second array elements---->
2
3
42
12
12
_________________
18. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
BEFORE swapping two arrays
first array
5
23
1
67
_________________
secondarrray
2
3
42
12
AFTER swap
first array
2
3
42
12
second array
5
23
1
67
19. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
_________________
LABLIST - 2 : EX.NO-6 Ascending and desceding order of number
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication19
{
class ascdes
{
int n;
int[] a = new int[10];
public void input()
{
Console.WriteLine("Enter the Number");
n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
Console.Write("Number[{0}]=", i);
a[i] = int.Parse(Console.ReadLine());
}
}
public void asc()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i] < a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
20. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("Ascending Order of Given Number:");
for (int i = 0; i < n; i++)
{
Console.WriteLine(a[i]);
}
}
public void des()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i] > a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
Console.WriteLine("Descending Order of Given Number:");
for (int i = 0; i < n; i++)
{
Console.WriteLine(a[i]); } } }
class Program
{ static void Main(string[] args)
{ int ch;
do
{
ascdes a = new ascdes();
Console.WriteLine("Ascending And Descending Order");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
a.input();
a.asc();
a.des();
Console.WriteLine("Do You want to perform again Press(1/0)");
ch = int.Parse(Console.ReadLine());
}
while (ch == 1);
Console.ReadLine();
21. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
} } }
OUTPUT: Ascending And Descending Order
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the Number 6
Number[0]=2
Number[1]=4
Number[2]=6
Number[3]=2
Number[4]=8
Number[5]=78
Ascending Order of Given Number:
2
2
4
6
8
78 Descending Order of Given Number:
78
8
6
4
2
22. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
2
LAB LIST - 2 : EX.NO-7 SUM OF DIAGONAL IN A MATRIX
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Text;
class mat
{
int i, j, m, n;
int[,] a = new int[20, 20];
public void get()
{
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 diag()
{
23. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
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 ma = new mat();
ma.get();
ma.diag();
Console.Read();
}
}
}
24. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
25. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LABLIST:2 EX.NO-8 LARGEST AND SMALLEST VALUES OF MATRIX
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication16
{
classrever
{
int[,] mat= newint[10,10];
int i,j,row,col,small,big;
publicvoid input()
{
Console.WriteLine("Enter the Number of Rows and Columns");
row = int.Parse(Console.ReadLine());
col = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Element of the Matrix");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
mat[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Elements in a Matrix");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
26. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.Write(mat[i,j]+"t");
}
Console.WriteLine();
}
}
publicvoid min()
{
big=mat[0,0];
small=mat[0,0];
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if(mat[i,j]<small)
small=mat[i,j];
if(mat[i,j]>big)
big=mat[i,j];
}
}
Console.WriteLine("Smallest Element in a Matrix={0}",small);
Console.WriteLine("Largest Element in a Matrix={0}",big);
}
}
classProgram
{
staticvoid Main(string[] args)
{
int ch;
do
{
rever r = newrever();
Console.WriteLine("Find Smallest And Largest value of a MAtrix");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
r.input();
r.min();
Console.WriteLine("Do You want to perform again Press(1/0)");
ch = int.Parse(Console.ReadLine());
}
while (ch == 1);
27. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.ReadLine();
}
}
}
Output:
Find Smallest And Largest value of a MAtrix
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the Number of Rows and Columns
3
3
Enter the Element of the Matrix
2
2
2
234
12
6
7
1
78
Elements in a Matrix
2 2 2
234 12 6
7 1 78
28. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Smallest Element in a Matrix=1
Largest Element in a Matrix=234
Lab List - 2 : EX.NO-9 NPR and NCR(Permitation and combination)
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
classncr
{
publicvoid ncr_met()
{
int n, r, per, fact, fact1, fact2;
Console.WriteLine("calculate NCR values");
Console.WriteLine("Enter the Value of 'n' and 'r' to find the Permutation :");
n = Convert.ToInt32(Console.ReadLine());
r = Convert.ToInt32(Console.ReadLine());
fact = n;
for (int i = n - 1; i >= 1; i--)
{
fact = fact * i;
}
fact2 = r;
for (int i = r - 1; i >= 1; i--)
{
fact2 = fact2 * i;
}
int number;
number = n - r;
fact1 = number;
for (int i = number - 1; i >= 1; i--)
{
fact1 = fact1 * i;
}
29. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
fact1 = fact2 * fact1;
per = fact / fact1;
Console.WriteLine("Combination : {0}", per);
}
publicvoid pnr_method()
{
int n, r, per, fact, fact1;
Console.WriteLine("Calculate NPR values");
Console.WriteLine("Enter the Value of 'n' and 'r' to find the Permutation :");
n = Convert.ToInt32(Console.ReadLine());
r = Convert.ToInt32(Console.ReadLine());
fact = n;
for (int i = n - 1; i >= 1; i--)
{
fact = fact * i;
}
int number;
number = n - r;
fact1 = number;
for (int i = number - 1; i >= 1; i--)
{
fact1 = fact1 * i;
}
per = fact / fact1;
Console.WriteLine("Permutation : {0}", per);
}
}
classsu_method
{
publicstaticvoid Main(string[] args)
{
int ch;
do
{
ncr np = newncr();
np.ncr_met();
np.pnr_method();
Console.WriteLine("do u want to continue(1) or (0)");
ch = Int32.Parse(Console.ReadLine());
30. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
}
while (ch == 1);
Console.ReadLine();
}
}
}
OUPUT:
calculate NCR values
Enter the Value of 'n' and 'r' to find the Permutation :
4
5
Combination : 0
Calculate NPR values
Enter the Value of 'n' and 'r' to find the Permutation :
12
23
Permutation : -43545600
do u want to continue(1) or (0)
1
calculate NCR values
Enter the Value of 'n' and 'r' to find the Permutation :
5
4
Combination : 5
31. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Calculate NPR values
Enter the Value of 'n' and 'r' to find the Permutation :
2
1
Permutation : 2
do u want to continue(1) or (0)
32. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 2 : EX.NO-10 LCM and GCD OF GIVEN NUMBER
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
classpro_lcm
{
int a,b,n1,n2,swap,lcm,gcd;
publicvoid input()
{
Console.WriteLine("Enter the Number");
a = Int32.Parse(Console.ReadLine());
b = Int32.Parse(Console.ReadLine());
}
publicvoid calc()
{
n1 = a;
n2 = b;
while (n2 != 0)
{
swap= n2;
n2 = n1 % n2;
n1 = swap;
}
gcd=n1;
lcm = (a * b) / gcd;
Console.WriteLine("lcm of {0} and {1}is {2}", a, b, lcm);
Console.WriteLine("gcd of {0} and {1} is {2}", a, b, gcd);
}
}
33. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
classpro
{
publicstaticvoid Main(string[] args)
{
int ch;
do
{
pro_lcm pl = newpro_lcm();
pl.input();
pl.calc();
Console.WriteLine("do u want to continue(1) or(0)");
ch = Int32.Parse(Console.ReadLine());
} while (ch == 1);
}
}
}
OUTPUT:
Enter the Number
45
50
lcm of 45 and 50is 450
gcd of 45 and 50 is 5
do u want to continue(1) or(0)