Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Diagonal Matrix Program Check

This C++ code takes in the row and column sizes of a matrix from the user, inputs the elements of the matrix, and then checks if the matrix is a scalar matrix by verifying that all diagonal elements are equal and all off-diagonal elements are 0. It outputs whether the matrix is a scalar matrix or not based on the results of the check.

Uploaded by

M Bilal Shahzad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Diagonal Matrix Program Check

This C++ code takes in the row and column sizes of a matrix from the user, inputs the elements of the matrix, and then checks if the matrix is a scalar matrix by verifying that all diagonal elements are equal and all off-diagonal elements are 0. It outputs whether the matrix is a scalar matrix or not based on the results of the check.

Uploaded by

M Bilal Shahzad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;

int main()

int row_size,col_size;

//Get size of matrix

cout<<"Enter the row Size Of the Matrix:";

cin>>row_size;

cout<<"Enter the columns Size Of the Matrix:";

cin>>col_size;

int matrix[row_size][col_size];

//Taking input of the matrix

int i,j;

cout<<"Enter the Matrix Element:\n";

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

for(j=0;j<col_size;j++)

cin>>matrix[i][j];

//check except Diagonal elements are 0 or not

//and check all diagonal elements are same or not

int point=0;

for(i=0;i<row_size;i++)
{

for(j=0;j<col_size;j++)

if(i!=j && matrix[i][j]!=0)

point=1;

break;

if(i==j && matrix[i][j]!=matrix[i][j])

point=1;

break;

if(point==1)

cout<<"Given Matrix is not a Scaler Matrix.";

else

cout<<"Given Matrix is a Scaler Matrix.";

You might also like