Question: C++ Programming using iostream and namespace std Write a function diagonalSum that takes in a 2-D array of int type and their row sizes and

C++ Programming using iostream and namespace std

Write a function diagonalSum that takes in a 2-D array of int type and their row sizes and returns sum of main diagonal(left diagonal) elements. (Assume column size is always 3)

int diagonalSum(int arr[][3], int row)

Example:

arr[3][3]= {{1, 4, 6}, {7, 23, 3}, {5, 15, 25}}

diagonal sum = 1+23+25

return value: 49

arr[3][3]= {{1, 4, -6}, {17, -23, 3}, {-5, 15, 5}}

diagonal sum = 1-23+5

return value: -17

arr[3][3] = {{-1, 4, 6}, {17, -3, 3}, {5, 15, 4}}

return value: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!