Write a program that reads in a table of numbers and finds out the average of each row and column. This program should first take two numbers as number of rows and columns as input from the user.
#include<iostream>
using namespace std;
int main()
{
int a[20][20],n,m,i,j,sum_row,sum_column;
cout<<"enter number of rows";
cin>>m;
cout<<"enter no of columns";
cin>>n;
cout<<"enter row and column values";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"entered table is\n";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
for(int i=0;i<m;i++)
{
sum_row = 0;
for(int j=0;j<n;j++)
{
sum_row = sum_row+a[i][j];
}
cout<<"\nAverage of row "<<i+1<<" is
"<<sum_row/n<<"\n";
}
for(int j=0;j<n;j++)
{
sum_column = 0;
for(int i=0;i<m;i++)
{
sum_column =
sum_column+a[i][j];
}
cout<<"\nAverage of column "<<j+1<<"
is "<<sum_column/m<<"\n";
}
return 0;
}
The Output is:
Hope this helps. If you like the answer please upvote. If you have any queries or suggestions regarding the answers please leave them in the comments section so I can update and improve the answer. Thank you.
Get Answers For Free
Most questions answered within 1 hours.