. Consider a nested tuple matrix=((10,20,30),(20,50,60),(10,40,60)). Do the operations such as find the sum of each row, find the average of each column, find the values of diagonal elements
Question
. Consider a nested tuple matrix=((10,20,30),(20,50,60),(10,40,60)). Do the operations such as find the sum of each row, find the average of each column, find the values of diagonal elements
Solution
Sure, let's break down the operations one by one.
-
Find the sum of each row:
For the first row (10, 20, 30), the sum is 10 + 20 + 30 = 60.
For the second row (20, 50, 60), the sum is 20 + 50 + 60 = 130.
For the third row (10, 40, 60), the sum is 10 + 40 + 60 = 110.
-
Find the average of each column:
For the first column (10, 20, 10), the average is (10 + 20 + 10) / 3 = 13.33.
For the second column (20, 50, 40), the average is (20 + 50 + 40) / 3 = 36.67.
For the third column (30, 60, 60), the average is (30 + 60 + 60) / 3 = 50.
-
Find the values of diagonal elements:
The diagonal elements are the ones where the row index and column index are the same. In this case, they are 10 (from the first row, first column), 50 (from the second row, second column), and 60 (from the third row, third column). So, the diagonal elements are 10, 50, and 60.
Similar Questions
Given a matrix, write a program to calculate the average of all its elements.Input:The input consists of two integers, m and n, representing the number of rows and columns in the matrix, respectively. This is followed by m lines, each containing n integers representing the elements of the matrix.Output:Print the average of all elements in the matrix.
Write a program to obtain a matrix and find the sum of its diagonal elements.Note: Only square matrix.Input format :The input consists of the number of rows and columns separated by a space.The second line of the input is matrix elements.Output format :The output prints the sum of diagonal elements.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :3 31 2 34 5 67 8 9Output 1 :15Input 2 :4 412 23 45 5678 89 98 8765 54 32 2114 25 36 58Output 2 :191
Write a C Program to Compute the Sum of Diagonals of a square matrix. Print the sum of both diagonals separately. Get the number of rows and columns from the user.
Write a program to obtain a matrix and find the sum of each row and each column.Input format :The first line of the input consists of the value of the number of rows and the number of columns.The second line of the input consists of a matrix.Output format :The output prints the sum of each row and each column.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :4 41 2 3 45 6 7 89 10 11 1213 14 15 16Output 1 :Sum of the row 0 = 10Sum of the row 1 = 26Sum of the row 2 = 42Sum of the row 3 = 58Sum of the column 0 = 28Sum of the column 1 = 32Sum of the column 2 = 36Sum of the column 3 = 40Input 2 :3 398 87 6545 32 2845 56 58Output 2 :Sum of the row 0 = 250Sum of the row 1 = 105Sum of the row 2 = 159Sum of the column 0 = 188Sum of the column 1 = 175Sum of the column 2 = 151
Write a program to obtain a matrix and find the sum of the elements in the lower triangular matrix.Note: Only square matrixInput format :The first line of the input consists of the number of rows and columns.The second line of the input consists of the matrix element.Output format :The output prints the sum of the lower triangular matrix.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :3 312 23 4556 78 8995 51 20Output 1 :312
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.