answersLogoWhite

0


Best Answer

#include<iostream>

#include<random>

#include<time.h>

int main()

{

std::default_random_engine generator ((unsigned)time(0));

std::uniform_int_distribution<int> distribution (1,9);

std::cout << "Array:\n" << std::endl;

int a[3][3];

for (size_t r=0; r!=3; ++r)

{

for (size_t c=0; c!=3; ++c)

{

a[r][c] = distribution (generator);

std::cout << a[r][c] << '\t';

}

std::cout << std::endl;

}

std::cout << std::endl;

int diagonal=0, anti_diagonal=0;

for (size_t i=0; i!=3; ++i)

{

diagonal += a[i][i];

anti_diagonal += a[2-i][i];

}

std::cout << "Diagonal sum : " << diagonal << std::endl;

std::cout << "Anti-diagonal sum : " << anti_diagonal << std::endl;

}

User Avatar

Wiki User

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

Wiki User

12y ago

#include<iostream.h>

#include<conio.h>

void main()

{ int a=0,b=0,i,j,s,c[10][10]; //initialising matrix

cout<<"Enter size of square of Matrix \n";

cin>>s;

cout<<"Enter Values into Matrix of side(s) "<<s<<"\n";

for(i=0; i<s; i++) // Input Matrix

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

{ cin>>c[i][j]; }

}

cout<<"\nThe Given Matrix is\n"; // Output MAtrix

for(i=0; i<s; i++)

{ cout<<"\n"; for(j=0; j<s; j++)

{ cout<<c[i][j]; }

}

cout<<"\n";

for(i=0; i<s; i++) // Loop to add elemnts below main diagonal

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

if(i>j) a + = c[i][j]; }

for(i=0; i<s; i++) // Loop to add elements above main diagonal

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

if(i<j) b + = c[i][j]; }

cout<<"\nSum of elements above the main diagonal is : "<<b;

cout<<"\nSum of elements below the main diagonal is : "<<a

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<conio.h>

#include<stdio.h>

void main()

{

int a[4][4],i,j,sum=0;

clrscr();

printf("enter 4*4 marks\n");

for(i=0;i<4;i++)

{

for{j=0;j<4;j++)

{

scanf("%d.&a[i][j]);

}

}

for

(i=0;i<4;i++)

{

sum=sum+a[i][j];

}

printf("sum of diagonal1=%d,sum);

sum=0;

for(i=0;i<4;i++)

{

sum+sum+a[i][3-1];

}

printf("\n sum of diagonal2=%d"sum);

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to input the square matrix and display the sum of diagonal elements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.


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