0% found this document useful (0 votes)
3 views

Lab7-Mech

Lab 7 focuses on multidimensional arrays in computer programming, specifically their declaration, initialization, and access methods. It includes various exercises such as reading and printing matrices, finding sums and products, transposing matrices, and interchanging rows. The document provides example C programs for each exercise to illustrate the concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab7-Mech

Lab 7 focuses on multidimensional arrays in computer programming, specifically their declaration, initialization, and access methods. It includes various exercises such as reading and printing matrices, finding sums and products, transposing matrices, and interchanging rows. The document provides example C programs for each exercise to illustrate the concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Lab 7

Computer Programming
ECO 123

12/10/2021 1
Lab 7
Lab objectives
1. Notes on multidimensional Arrays
2. Exercises on multidimensional Arrays
• Multidimensional Arrays

12/10/2021 2
Declaration of an Array:

Declaration of 2D array is same as one dimension except that we


give the size of the array expressed into rows and columns.
Arraytype Arrayname [No.rows][No.columns]

Ex:
int num[2][2]; //Array of 2 rows and 2 columns of integer numbers
integers

12/10/2021 3
Initialization of an Array:

Different ways to initialize arrays:


int num[2] [2]= {{19, 10},{17, 9}};
int num [2][2]={1,2,3,4};
int num[2][2];

12/10/2021 4
To access any element of the array we simply write the array name
and the element index.

Ex:-
int Numbers[3][3];
Numbers[2][1]=3; //Setting the element in third row and second
column to 3

12/10/2021 5
Ex1: C Program to read and print a RxC
Matrix, R and C must be input by User

12/10/2021 6
12/10/2021 7
12/10/2021 8
Ex2: C Program to read a matrix and find sum,
product of all elements of two dimensional
(matrix) array

12/10/2021 9
12/10/2021 10
12/10/2021 11
Ex3: C program to transpose a matrix

12/10/2021 12
12/10/2021 13
Ex4: C program to read a matrix and print it's
diagonals.

12/10/2021 14
12/10/2021 15
12/10/2021 16
Ex5: C program to find sum and subtraction
of two matrices

12/10/2021 17
12/10/2021 18
12/10/2021 19
12/10/2021 20
12/10/2021 21
Ex6: C program to find multiplication of two matrices

12/10/2021 22
12/10/2021 23
12/10/2021 24
12/10/2021 25
12/10/2021 26
Ex7: C program to interchange the rows in
the matrix

12/10/2021 27
12/10/2021 28
12/10/2021 29
12/10/2021 30
Ex8: C program to arrange row elements in
ascending order.

12/10/2021 31
12/10/2021 32
12/10/2021 33
12/10/2021 34

You might also like