answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <conio.h>

void main() {

int d[3][3] = { 1, 2, 6, 3, 8, 5, 5, 6, 7 };

int k = 0, j = 0;

int sum1 = 0, sum2 = 0;

for (j = 0; j < 3; j++) {

for (k = 0; k < 3; k++)

printf(" %3d", d[j][k]);

printf("\n");

}

for (j = 0; j < 3; j++) {

sum1 = sum1 + d[j][j];

}

k = 3 - 1;

for (j = 0; j < 3; j++) {

if (k >= 0) {

sum2 = sum2 + d[j][k];

k--;

}

}

printf("Sum of First diagonal= %d\n", sum1);

printf("Sum of Second diagonal= %d", sum2);

getch();

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

1d ago

Here is a simple C program to achieve this:

#include <stdio.h>

int main() {
    int matrix[3][3];
    int i, j, sum = 0;

    // Accept elements of the matrix
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            printf("Enter element at position [%d][%d]: ", i, j);
            scanf("%d", &matrix[i][j]);

            // Add to sum if it is on the major diagonal
            if (i == j) {
                sum += matrix[i][j];
            }
        }
    }

    // Print the matrix
    printf("Matrix:\n");
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }

    // Print the sum of major diagonal elements
    printf("Sum of major diagonal elements: %d\n", sum);

    return 0;
}

This program prompts the user to enter elements for a 3x3 matrix, calculates the sum of the major diagonal elements, and then prints the inputted matrix along with the sum of the major diagonal elements.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to accept the elements of a 3 x 3 matrix and find its sum of the major diagonal elements The program should print the given matrix along with its sum of the major diagonal elements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Educational Theory

C program to find sum of all elements of a matrix?

To find the sum of all elements in a matrix in C, you can use nested loops to iterate through each element and accumulate the sum. Here is a basic example: #include &lt;stdio.h&gt; #define ROWS 3 #define COLS 3 int main() { int matrix[ROWS][COLS] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int sum = 0; for(int i = 0; i &lt; ROWS; i++) { for(int j = 0; j &lt; COLS; j++) { sum += matrix[i][j]; } } printf(&quot;Sum of all elements in the matrix: %d\n&quot;, sum); return 0; }


What does post matrix study mean?

Post-matrix study refers to research or analysis conducted after a matrix has been created. It involves examining the results, patterns, or implications identified through the matrix and drawing conclusions or recommendations based on this study. The goal is to deepen understanding, resolve issues, or make informed decisions using the information provided by the matrix.


What is the purpose of a cause-and-effect matrix?

A cause-and-effect matrix is used to analyze the relationship between different variables in a process and determine how they influence each other. It helps in identifying the key factors that contribute to a particular outcome or problem, enabling organizations to prioritize their efforts on addressing the root causes of issues.


Which of these will help you prioritize the items on your to-do list?

Using three groups to show how important each item is


What is the difference between think and believe?

&quot;Think&quot; is used to express opinions or ideas that one holds based on reason or knowledge. &quot;Believe&quot; is used to express acceptance of something as true, often based on faith or trust rather than proof. Essentially, thinking tends to involve more logical reasoning, while belief involves more emotional conviction.

Related questions

Is the scalar matrix is always a identity matrix?

No. A scalar matrix is a diagonal matrix whose main diagonal elements are the same. Only if the diagonal elements are all 1 is it an identity matrix.


Is a matrix multiplied by its transpose diagonalisable?

It will be a square matrix and, to that extent, it is diagonalisable. However, the diagonal elements need not be non-zero. It will be a square matrix and, to that extent, it is diagonalisable. However, the diagonal elements need not be non-zero. It will be a square matrix and, to that extent, it is diagonalisable. However, the diagonal elements need not be non-zero. It will be a square matrix and, to that extent, it is diagonalisable. However, the diagonal elements need not be non-zero.


What is the determinant of a 3x3 diagonal matrix?

It is the product of the three diagonal elements.


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


What is the determinant of a 3x3 matrix?

It is the product of the three diagonal elements.


What is scalene matrix?

A square matrix is said to be scalene Matrix if it has all principal diagonal elements equal and remaining all


What is the definition of a diagonal matrix?

Diagonal Matrix A square matrix A which is both uper-triangular and lower triangular is called a diagonal matrix. Diagonal matrix is denoted by D.


What is the definition of a matrix?

Symmetric Matrix:Given a square matrix A such that A'=A, where A' is the transpose of A, then A is a symmetric matrix.note: No need to think about diagonal elements, they can be anything.


what is the definition of The Matrix?

Symmetric Matrix:Given a square matrix A such that A'=A, where A' is the transpose of A, then A is a symmetric matrix.note: No need to think about diagonal elements, they can be anything.


What is the definition of a symmetric matrix?

Symmetric Matrix:Given a square matrix A such that A'=A, where A' is the transpose of A, then A is a symmetric matrix.note: No need to think about diagonal elements, they can be anything.


Write a c program on reverse the diagonal element of matrix?

mano ni anda yarrr


What is strictly lower triangular matrix?

A strictly lower triangular matrix is a kind of (lower) triangular matrix. Term "lower" implies matrix has elements only in the lower half. The condition "strictly" implies that even the "diagonal" of such lower triangular matrix is populated with '0's. The strictly lower triangular matrix thus has '0's in its diagonal as well as the upper triangle part. In other words, a strictly lower triangular matrix is a lower triangular matrix minus its diagonal.