









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
DSA LABS TASK THAT CAN HELP YOU IN FUTURE
Typology: Assignments
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Submitted By: ____MUHAMMAD USMAN KHAN______65171______
Submitted To: Engr. Dr. Farah/ Engr. Saniya Sarim
Signed Remarks: Score: INDEX
01 25/09/ 20 01 ARRAY
LAB EXPERIMENT NO. __01_____ LIST OF TASKS
(^01) Q. Create an array of length 10 of integers. Values ranging from 1 to
Find all pair of elements whose sum is 25.
Find the number of elements of A which are even, and the number of elements of A which are odd.
Write a procedure which finds the average of the value of A.
Write a procedure which adds an element in an array at a given index. Take the value to add and the index from the user by using Shift down technique.
Write a procedure which looks for 2 numbers 45 and 14 in an array and delete them if they are present in the array by using Shift up technique. (^02) 1. Write a program which input 2 matrix of user defined rows and columns and perform following operation a. Display/Print as a Matrix
b. Addition of Matrix c. Subtraction of Matrix d. matrix multiplication e. Determinant f. Inverse Submitted On: ____2/10/2020________
Console.WriteLine("{0} + {1} = 25", arr[i], arr[j]); count++; } } } Console.WriteLine("{0} pair in an Array whoes sum is {1}", count, n); Console.WriteLine(" "); return false; } public void evenOrOdd(int[] arr) { Console.WriteLine("\t2) EVEN AND ODD"); Console.WriteLine(" "); int even = 0; int odd = 0; for (int j = 0; j < arr.Length; j++) { Console.WriteLine("ELEMENT [{0}]={1}", j, arr[j]); if (arr[j] % 2 == 0) { even++; } if (arr[j] % 2 != 0) { odd++; } } Console.WriteLine("The Element is even: {0}", even); Console.WriteLine("The Element is odd: {0}", odd); Console.WriteLine(" "); } public void Average(int[] arr) { Console.WriteLine("\t 3) AVERAGE"); Console.WriteLine(" "); int sum = 0; for (int i = 0; i < arr.Length; i++) { sum += arr[i]; } Console.WriteLine("AVERAGE:{0}", sum / arr.Length); Console.WriteLine(" "); } public void shiftdown(int[] arr) { Console.WriteLine("\t 4) INSERTION"); Console.WriteLine(" "); Console.WriteLine("Enter the number for insertion:"); int x; x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the number for Index:"); int pos; pos = Convert.ToInt32(Console.ReadLine());
int[] newarr = new int[arr.Length + 1]; for (int i = 0; i < newarr.Length; i++) { if (i < pos - 1) { newarr[i] = arr[i]; } else if (i == pos - 1) { newarr[i] = x; } else { newarr[i] = arr[i - 1]; } } for (int i = 0; i < arr.Length + 1; i++) { Console.Write(newarr[i] + " "); } Console.WriteLine(""); } public void shiftup(int[] arr,int l) { Console.WriteLine("\t 5) Delete"); Console.WriteLine(" "); int[] newarr1 = new int[arr.Length]; for (int i = 0; i < l; i++) { if (newarr1[i] == 45 || newarr1[i] == 14) { newarr1[i] = 0; } else { newarr1[i] = arr[i]; } } foreach (int a in newarr1) { Console.Write("{0} ", a); } Console.WriteLine(""); Console.ReadLine(); } } }
and perform following operation a. Display/Print as a Matrix b. Addition of Matrix c. Subtraction of Matrix d. matrix multiplication e. Determinant f. Inverse
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TASk_ { class Program { static void Main(string[] args) { int r; int c; Array a = new Array(); Console.WriteLine("Enter No.of rows for matrix: "); r = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter No.of columns for matrix: "); c = Convert.ToInt32(Console.ReadLine()); int[,] mat1 = new int[r, c]; int[,] mat2 = new int[r, c]; int[,] ADD = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { Console.Write("element - [{0},{1}] : ", i, j); mat1[i, j] = Convert.ToInt32(Console.ReadLine()); } } for (int i = 0; i < r; i++) { Console.Write("\n"); for (int j = 0; j < c; j++) {
Console.Write("{0}\t", mat1[i, j]); } Console.Write("\n"); } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { Console.Write("element - [{0},{1}] : ", i, j); mat2[i, j] = Convert.ToInt32(Console.ReadLine()); } } for (int i = 0; i < r; i++) { Console.Write("\n"); for (int j = 0; j < c; j++) { Console.Write("{0}\t", mat2[i, j]); } Console.Write("\n"); } a.addition(ADD, mat1, mat2, r, c); a.subtraction(ADD, mat1, mat2, r, c); a.multiplication(ADD, mat1, mat2, r, c); a.determinant(mat1, r, c); a.inverse(mat1, r, c); } } class Array { public void addition(int[,] crr, int[,] arr, int[,] brr, int r, int c) { Console.WriteLine("\t\t\t\t ADDITION OF 2 MATRIX "); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { crr[i, j] = arr[i, j] + brr[i, j]; } } Console.Write("\nThe Addition of two matrix is : \n"); for (int i = 0; i < r; i++) { Console.Write("\n"); for (int j = 0; j < c; j++) { Console.Write("{0}\t", crr[i, j]); }
Console.Write("\n\n"); } public void determinant(int[,] arr, int r, int c) { Console.WriteLine("\t\t\t\t DETERMINENT OF MATRIX "); int determinant = 0; determinant = (arr[0, 0] * arr[1, 1]) - (arr[0, 1] * arr[1, 0]); Console.Write("\nThe Determinant of two matrix is : \n"); Console.WriteLine(determinant); } public void inverse(int[,] arry, int r, int c) { Console.WriteLine("\t\t\t\t INVERSE OF MATRIX "); float div; float[,] inverseArry = new float[2, 2]; div = 1 / arry[0, 0] * arry[1, 1] - arry[1, 0] * arry[0, 1]; inverseArry[0, 0] = arry[1, 1] / div; inverseArry[0, 1] = arry[0, 0] / div; inverseArry[1, 0] = -arry[0, 1] / div; inverseArry[1, 1] = -arry[1, 0] / div; Console.WriteLine("Inverse Matrixs "); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write("[" + inverseArry[i, j] + "]"); } Console.WriteLine(); } Console.ReadKey(); } } }