0% found this document useful (0 votes)
32 views1 page

Program To Find The Sum of Rows and Column of An Array

This program takes user input to define the number of rows and columns in a 2D array. It then inputs values into the array and outputs the matrix. For square matrices, it calculates the sum of the main diagonal elements and another diagonal. The sums are output.

Uploaded by

Himanshu Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Program To Find The Sum of Rows and Column of An Array

This program takes user input to define the number of rows and columns in a 2D array. It then inputs values into the array and outputs the matrix. For square matrices, it calculates the sum of the main diagonal elements and another diagonal. The sums are output.

Uploaded by

Himanshu Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

5.

Program to find the sum of rows and column


of an array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],r,c,s1=0,s2=0,i,j;
cout<<"enter the no. of rows and columns\n";
cin>>r>>c;
cout<<"enter the array\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"Matrix is\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<endl;
}
if(r==c)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
s1=s1+a[i][j];
}
if((i+j)==2)
{
s2=s2+a[i][j];
}
}
}
cout<<"sum of main diagonal elements is="<<s1<<'\n';
cout<<"sum of another diagonal elements is="<<s2<<'\n';
}
else
cout<<"no diagonal sum possible\n";
getch();
}

You might also like