#include<iostream.h>
#include <conio.h>
#include<stdio.h>
void sum(int m,int n, int a[][10]) // sum of all the elements
{
int i,j;
int sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum=sum+a[i][j];
}
}
cout<<"sum of all the elements="<<sum<<"\n";
}
void sum_row(int m,int n, int a[][10]) // sum of the row wise elements
{
int i,j;
int sumr;
for(i=0;i<m;i++)
{
sumr=0;
for(j=0;j<n;j++)
{
sumr=sumr+a[i][j];
}
cout<<"sum of the "<<i+1<<" row elements="<<sumr<<"\n";
}
}
void main()
{
int a[10][10];
int b[3][2]={11,12,
13,14,
15,16};
int i,j,m,n;
cout<<"Enter m and n\n";
cin>>m>>n;
cout<<"Enter a matrix values\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"a matrix elements\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"a["<<i<<"]["<<j<<"]="<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"b matrix values\n";
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
sum(m,n,a);
sum_row(m,n,a);
}
#include <conio.h>
#include<stdio.h>
void sum(int m,int n, int a[][10]) // sum of all the elements
{
int i,j;
int sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum=sum+a[i][j];
}
}
cout<<"sum of all the elements="<<sum<<"\n";
}
void sum_row(int m,int n, int a[][10]) // sum of the row wise elements
{
int i,j;
int sumr;
for(i=0;i<m;i++)
{
sumr=0;
for(j=0;j<n;j++)
{
sumr=sumr+a[i][j];
}
cout<<"sum of the "<<i+1<<" row elements="<<sumr<<"\n";
}
}
void main()
{
int a[10][10];
int b[3][2]={11,12,
13,14,
15,16};
int i,j,m,n;
cout<<"Enter m and n\n";
cin>>m>>n;
cout<<"Enter a matrix values\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"a matrix elements\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"a["<<i<<"]["<<j<<"]="<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"b matrix values\n";
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
sum(m,n,a);
sum_row(m,n,a);
}
No comments:
Post a Comment