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

Assignment 4

Uploaded by

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

Assignment 4

Uploaded by

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

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.

Example for Symmetric matrix:

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.

7.Create a function that takes an integer then return true if this


number is prime otherwise return false.

8.Create a function that takes an integer then return true if this


number is even otherwise return false.

9. Write a function that takes an integer and return


the cube of the given number.

Input any number: 5


Output
Cube of 5 = 125

10.Write a program to take radius of circle from user and find


diameter, circumference and area of the given circle using
function.

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.

You might also like