In: Computer Science
Write a C++ 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
// Here is your required code
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int row,column,i,j,sum1=0,sum2=0;
int average1,average2;
cout<<"Enter the row and column"<<endl;
cin>>row>>column;
int arr[row][column];
for(i=0;i<row;i++)
for(j=0;j<column;j++)
cin>>arr[i][j];
system("cls");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
cout<<arr[i][j]<<" ";
cout<<endl;
}
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
sum1=sum1+arr[i][j];
}
average1=sum1/column;
cout<<"The Average of "<<i+1<<" row "<<average1<<endl;
sum1=0;
}
for(i=0;i<column;i++)
{
for(j=0;j<row;j++)
{
sum2=sum2+arr[j][i];
}
average2=sum2/row;
cout<<"The Average of "<<i+1<<" column "<<average2<<endl;
sum2=0;
}
return 0;
}
Output:
Note: If you have any query do write it in comment section
Please hit the like button if you find this helpful for you THANK YOU AND HAPPY LEARNING:)