C Exercises: Find the sum of left diagonals of a matrix
24. Left Diagonal Sum
Write a program in C to find the sum of the left diagonals of a matrix.
The task is to write a C program that calculates the sum of the elements along the left diagonal of a square matrix. The program prompts the user to input the size of the matrix and its elements, computes the sum of the elements from the top-left to bottom-right diagonal, and displays both the matrix and the sum of its left diagonal elements as output.
Visual Presentation:
Sample Solution:
C Code:
Sample Output:
Find sum of left diagonals of a matrix : --------------------------------------- Input the size of the square matrix : 2 Input elements in the first matrix : element - [0],[0] : 1 element - [0],[1] : 2 element - [1],[0] : 3 element - [1],[1] : 4 The matrix is : 1 2 3 4 Addition of the left Diagonal elements is :5
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to compute the sum of the secondary diagonal elements of a matrix.
- Write a C program to display the left diagonal of a matrix and then calculate the average of these elements.
- Write a C program to compute the left diagonal sum using pointer arithmetic on a 2D array.
- Write a C program to compute and compare the left and right diagonal sums of a square matrix.
Go to:
PREV : Right Diagonal Sum.
NEXT : Sum of Rows & Columns.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
