#include<iostream>
using namespace std;
void colsum(int [][30],int [],int,int);
int main()
{
int a[30][30],b[30],m,n,i,j;
cout<<"Enter row size: ";
cin>>m;
cout<<"Enter column size: ";
cin>>n;
cout<<"\n\nEnter the matrix: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
cin>>a[i][j];
}
cout<<"\n\nThe matrix is: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\nThe column sum of the matrix is: \n\n";
colsum(a,b,m,n);
for(i=0;i<n;++i)
cout<<b[i]<<" ";
return 0;
}
void colsum(int a[][30],int b[],int m,int n)
{
int i,j;
b[n];
for(j=0;j<n;++j)
{
b[j]=0;
for(i=0;i<m;++i)
{
b[j]+=a[i][j];
}
}
}
using namespace std;
void colsum(int [][30],int [],int,int);
int main()
{
int a[30][30],b[30],m,n,i,j;
cout<<"Enter row size: ";
cin>>m;
cout<<"Enter column size: ";
cin>>n;
cout<<"\n\nEnter the matrix: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
cin>>a[i][j];
}
cout<<"\n\nThe matrix is: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\nThe column sum of the matrix is: \n\n";
colsum(a,b,m,n);
for(i=0;i<n;++i)
cout<<b[i]<<" ";
return 0;
}
void colsum(int a[][30],int b[],int m,int n)
{
int i,j;
b[n];
for(j=0;j<n;++j)
{
b[j]=0;
for(i=0;i<m;++i)
{
b[j]+=a[i][j];
}
}
}
0 comments:
Post a Comment