Answers for "c ++ Program for addition of two matrix in diagonal using pointers"

C++
0

c ++ Program for addition of two matrix in diagonal using pointers

/* C++ program for Sum of diagonal elements of a matrix */
#include<iostream>
using namespace std;
int main()
{
	int matrix[100][100], m, n ,i ,j, sum=0;
	cout<<"Enter rows of matrix: ";
	cin>>m;
	cout<<"Enter columns of matrix: ";
	cin>>n;
 
	cout<<"Enter matrix elements: "<<endl;
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>matrix[i][j];
		}
	}
 
	/* add diagonal elements into sum */
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i==j)
			sum=sum+matrix[i][j];
		}
	}
 
	cout<<"Sum of diagonal elements: "<<sum;
 
	return 0;	
}
Posted by: Guest on July-25-2020

Code answers related to "c ++ Program for addition of two matrix in diagonal using pointers"

Browse Popular Code Answers by Language