Assignment 4
Assignment 4
2D Array Tasks:
1. Write a program to read elements in a matrix and find the sum of main
diagonal (major diagonal) elements of the matrix.
Input array elements:
123
456
789
Output
Sum of main diagonal elements = 15
2. Write a program to read elements in two matrices and add elements of
both matrices.
Input
Input elements in 3x3 matrix1:
123
456
789
Input elements in 3x3 matrix2:
987
654
321
Output
Sum of both matrix =
10 10 10
10 10 10
10 10 10
3. Write a program to read elements in a matrix and find the sum of elements
of each row of the matrix.
Input elements in array:
123
456
789
Output
Sum of row 1 = 6
Sum of row 2 = 15
Sum of row 3 = 24
4. Write a CPP program to read elements in a matrix and check whether the
given matrix is a symmetric matrix or not.
123
245
358
What is a Symmetric Matrix?
.
A symmetric matrix is a square matrix which is equal to its transpose. A
symmetric matrix is always a square matrix. Symmetric matrix A is defined as –
A = AT
Functions Tasks:
Create a void function that takes an integer then print it then call this
5.
method in main.
6. Create a function that takes three integers then return the average as
float value then call this method in main.
Input radius: 10
Output
Diameter = 20 units
Circumference = 62.83 units
Area = 314.16 sq. units
11. create void function that takes a number and print all divisors of this number.
12. create function that takes a number and return true if this number can be
divided by 3 and 4.