0% found this document useful (0 votes)
67 views2 pages

Cse115 Lab Manual 16 2D Array

Uploaded by

tasin.nextlab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

Cse115 Lab Manual 16 2D Array

Uploaded by

tasin.nextlab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 115 Lab on 2D Array – Ara2

1. C program to find transpose of a 3*3 matrix:


#include <stdio.h>

void main()
{
int A[3][3], B[3][3], row, col;

printf("Enter elements in matrix of size 3x3: \n");


for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
scanf("%d", &A[row][col]);
}
}

// Compute matrix B: the transpose of matrix A


for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
//Store each row of A to each column of matrix B
B[row][col] = A[col][row];
}
}

// Prints the original matrix A


printf("\nOriginal matrix: \n");
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
printf("%d ", A[row][col]);
}
printf("\n");
}

// Prints the transpose of matrix A


printf("Transpose of matrix A: \n");
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
printf("%d ", B[row][col]);
}
printf("\n");
}
}
Exercise:
1. Write C program to read a 3*5 matrix A from user and print the elements of the
matrix n*A where n is a decimal number read from user.
2. Write C program to read a n*n matrix A from user (n is a user input) and print the (i)
upper left, (ii) lower right, (iii) upper right, and (iv) lower left triangle, (v) diagonal and
(vi) reverse diagonal of A.
3. Write C program to read a r*c matrix A from user (r, c are user inputs) and print the
sum of even numbers in A.

Assignment:
1. Write a C program to find sum of border elements (bold ones) of a matrix
Example:
If the array elements are:
1234
4567
7899
Output should be: Sum of main border elements = 54
because 1+2+3+4+7+9+9+8+7+4 = 54

2. Write C program to read two r*c matrices A and B from user (r, c are user inputs) and
print the matrix 5A+7B+9 (add 9 with each element of the matrix 5A+7B to get the
resultant matrix).

3. Write a C program to compute determinant of a 3X3 matrix

You might also like