You are on page 1of 9

Bahria University,

Karachi Campus

COURSE: CSC-113 COMPUTER PROGRAMMING


TERM: FALL 2019, CLASS: BSE- 1 (B)

Submitted By:

____Zain Rizvi________________________46064_______
(Name) (Reg. No.)
Submitted To:

Engr. Adnan ur rehman/ Engr. Ramsha Mashood

1
[Lab no.10] [Computer Programming]
[2D-Array]
Signed Remarks: Score:

Bahria University,
Karachi Campus

LAB EXPERIMENT NO.


____10___
LIST OF TASKS
TASK NO OBJECTIVE
1 Enter the first matrix and then display it. Secondly, enter the second matrix and then display it.
In the result by apply 2D arrays show Addition, subtraction of 2 matrixes.
2 : Take N number of user data input and make sure N is greater than 10, which contain name of
the user, his/her nationality and his/her eye color. You have to show the max
3 Make a program in C# in which take no. of items, price of items,quantity of items and name of
items as input from the user and give the discount according to the following conditions (Use 2D
Array):

Submitted On:
12/ dec /2020
(Date: DD/MM/YY)
[Lab no.10] [Computer Programming]
[2D Arrays]
Task No. 1: Enter the first matrix and then display it. Secondly, enter the second matrix and
then display it. In the result by apply 2D arrays show Addition, subtraction of 2 matrixes.

Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lab_10
{
class matrix_add
{
public void add()
{
Console.WriteLine("Input Matrix 1");
int[,] matrix1 = new int[3, 3];

for (int i = 0; i < 3; i++)


{
for (int j = 0; j < 3; j++)
{
Console.Write("Matrix[" + i + "][" + j + "]:");
matrix1[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.WriteLine("Input Matrix 2");
int[,] matrix2 = new int[3, 3];

for (int i = 0; i < 3; i++)


{
for (int j = 0; j < 3; j++)
{
Console.Write("Matrix[" + i + "][" + j + "]:");
matrix2[i, j] = Convert.ToInt16(Console.ReadLine());
}
}

int[,] add = new int[3, 3];


int[,] sub = new int[3, 3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
add[i, j] = matrix1[i, j] + matrix2[i, j];
sub[i, j] = matrix1[i, j] - matrix2[i, j];

}
}

Console.WriteLine("output addition Matrix");


for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
[Lab no.10] [Computer Programming]
[2D Arrays]
{
Console.Write(add[i, j] + " ");
}
Console.WriteLine();
}

Console.WriteLine("output subtraction Matrix");


for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(sub[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadKey();

}
}
}

Output:
[Lab no.10] [Computer Programming]
[2D-Array]

Task No 2: Take N number of user data input and make sure N is greater than 10, which
contain name of the user, his/her nationality and his/her eye color. You have to show the max
Solution:
class task2
{
public void task() {
string[] head = new string[3];
string[,] matrix = new string[11, 3];
string[] matrix1 = new string[5];
int[] mat2 = new int[5];
matrix1[0] = "Pakistan";
matrix1[1] = "India";
matrix1[2] = "Korea";
matrix1[3] = "Canada";
matrix1[4] = "Us";
head[0] = "Name:";
head[1] = "Nationality:";
head[2] = "eye color:";
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(head[j] + " ");
matrix[i,j] = Console.ReadLine();
}
Console.WriteLine("\n\n");
}

for (int i = 0; i < 11; i++)


{
for (int k = 0; k < 5; k++)
{
if (matrix1[ k] == matrix[i, 1])
{
if (mat2[k] == null)
{
mat2[k] = 1;
}
else {
mat2[k] = mat2[k] + 1;
}
}
}

Console.WriteLine();
}

for (int i = 0; i < 5; i++)


{
Console.WriteLine(matrix1[i] + " " + mat2[i]);
}

Console.ReadKey();
[Lab no.10] [Computer Programming]
[2D-Array]
}
}

Output:
[Lab no.10] [Computer Programming]
[2D-Array]

Task 3: Make a program in C# in which take no. of items, price of items,quantity of items and name of items
as input from the user and give the discount according to the following conditions (Use 2D Array):

Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lab_10
{
class task3
{
public void t3()
{
Console.Write("Enter number of items");
//3. Make a program in C# in which take no. of items,

// price of items,
// quantity of items and name of items as input from the user and give the
discount according to the following conditions

int i = Convert.ToInt16(Console.ReadLine());

string[,] arr1 = new string[4, 6];


arr1[0, 0] = "item num";
arr1[0, 1] = "price of item"
; arr1[0, 2] = "qty";
arr1[0, 3] = "name";
arr1[0, 4] = "discount";
arr1[0, 5] = "total";
for (int ij = 1; ij < 4; ij++)
{
for (int j = 0; j <= 5; j++)
{
if (j == 4)
{
if (arr1[ij, 4] == "rice")
arr1[ij, j] = "30%";
else
{
arr1[ij, j] = "0";
}
}
else if (j == 5)
{
arr1[ij, j] = Convert.ToString(Convert.ToInt16(arr1[ij, 1]) *
Convert.ToInt16(arr1[ij, 2]));
[Lab no.10] [Computer Programming]
[2D-Array]
if (arr1[ij, 4] == "30%")
{
arr1[ij, j] = Convert.ToString(Convert.ToInt16(arr1[ij, j]) * 0.30);
}
}
else
{
Console.Write("Enter " + arr1[0, j]);
arr1[ij, j] = Console.ReadLine();
}
}
Console.WriteLine();
}
double total = 0;
for (int ij = 1; ij < 4; ij++)
{
total = total + Convert.ToDouble(arr1[ij, 5]);

for (int ij = 1; ij < 4; ij++)


{
for (int j = 0; j <= 5; j++)
{
Console.WriteLine(arr1[0, j] + "=" + arr1[ij, j]);

}
Console.WriteLine();
}
Console.Write("Total=" + total);
Console.ReadKey();
}
}
}

Output:
[Lab no.10] [Computer Programming]
[2D-Array]

You might also like