Row sum is a matrix operation in which the elements of each row are added and stored
in a different array.......
Program:
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
void rowsum(int a[][30],int b[],int m,int n)
{
int i,j;
b[m];
for(i=0;i<m;++i)
{
b[i]=0;
for(j=0;j<n;++j)
{
b[i]+=a[i][j];
}
}
}
int main()
{
system("cls");
cout<<setw(54)<<"*****-------------------*****\n";
cout<<setw(54)<<"*****ROW SUM OF A MATRIX*****\n";
cout<<setw(54)<<"*****-------------------*****\n";
cout<<"\n\n";
int a[30][30],b[30],m,n,i,j;
cout<<"\tEnter row size: ";
cin>>m;
cout<<"\tEnter column size: ";
cin>>n;
cout<<"\n\n\tEnter matrix elements: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<"\tEnter ["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
Sleep(1000);
system("cls");
cout<<"\n\n\n\t\t\tThe matrix is: \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n\t\t\tProcessing.......";
Sleep(2200);
cout<<"\n\n\n\t\tThe row sum of the matrix is: \n\n";
rowsum(a,b,m,n);
for(i=0;i<m;++i)
cout<<"\t\t\tRow"<<i+1<<" : "<<b[i]<<"\n";
return 0;
}
Output:
in a different array.......
Program:
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
void rowsum(int a[][30],int b[],int m,int n)
{
int i,j;
b[m];
for(i=0;i<m;++i)
{
b[i]=0;
for(j=0;j<n;++j)
{
b[i]+=a[i][j];
}
}
}
int main()
{
system("cls");
cout<<setw(54)<<"*****-------------------*****\n";
cout<<setw(54)<<"*****ROW SUM OF A MATRIX*****\n";
cout<<setw(54)<<"*****-------------------*****\n";
cout<<"\n\n";
int a[30][30],b[30],m,n,i,j;
cout<<"\tEnter row size: ";
cin>>m;
cout<<"\tEnter column size: ";
cin>>n;
cout<<"\n\n\tEnter matrix elements: \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<"\tEnter ["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
Sleep(1000);
system("cls");
cout<<"\n\n\n\t\t\tThe matrix is: \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n\t\t\tProcessing.......";
Sleep(2200);
cout<<"\n\n\n\t\tThe row sum of the matrix is: \n\n";
rowsum(a,b,m,n);
for(i=0;i<m;++i)
cout<<"\t\t\tRow"<<i+1<<" : "<<b[i]<<"\n";
return 0;
}
Output:
0 comments:
Post a Comment