Question: Write a C + + program to add the elements on the two diagonals of a square two dimensional integer array and display that sum.

Write a C++ program to add the elements on the two diagonals of a square two dimensional integer array and display that sum. Ensure that if there is a middle element in the array it is not counted twice in the sum.
For example, with the array:
1234
5678
9101112
13141516
your program should display 68(1+6+11+16+4+7+10+13).
With the array:
123
567
91011
your program should display 30(1+6+11+3+9)(note that the 6 is not counted twice).

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!