In C write a program that creates a twodimensional array ini

In C++, write a program that creates a two-dimensional array initialized with some integers. Have the following six functions: Total (total of all values in array), Average (average of values in array), Total of specific row (this needs 2 arguments, the array, like the others, and an integer for the subscript of any row. Total of specific Column (same as row), Max value in Row ( same as previous two, but return the highest value), Minimum Value ( same as previous).

Solution

#include <iostream>

using namespace std;

int main()
{   

int i,j,s=0,sum=0;
int x, y;

cout<<\"Enter the rows count for your 2- D array \ \";
cin>>x;
cout<<endl;

cout<<\"Enter the columns count for your 2- D array \ \";
cin>>y;
cout<<endl;

int mul=0;
mul = x*y;

int a[x][y];
int total=0;

cout<<\"Enter \"<<mul<<\" elements of \"<<x<<\"*\"<<y<<\" Matrix \ \";
for(i=0;i<x;i++){
for(j=0;j<y;j++){
cin>>a[i][j];
total=total+a[i][j];
}
}
cout<<endl;

cout<<\"Matrix Entered By you is \ \";
for(i=0;i<x;i++)
{for(j=0;j<y;j++)
cout<<a[i][j]<<\" \";

cout<<endl;
}

cout<<\"The total of \"<<mul<<\" elements is \"<<total<<\"\ \";

float avg;
avg = total/mul;
cout<<\"The average of \"<<mul<<\" elements is \"<<avg<<\"\ \";

int b,c;

cout<<\"Enter a row subscript to add the values \ \";
cin>>b;
cout<<endl;


for(j=0;j<y;j++){
s=s+a[b][j];

}
cout<<\"sum of\"<<b<<\" Row is\"<<s;
cout<<endl;
  
  
cout<<\"Enter a column subscript to add the values \ \";
cin>>c;
cout<<endl;

int r=0;
for(i=0;i<x;i++)
{
r=r+a[i][c];

}
cout<<\"sum of\"<<c<<\" Column is\"<<r;
cout<<endl;
int d;

cout<<\"Enter a row subscript where we need to find max value \ \";
cin>>d;
cout<<endl;

int max=0;
for(j=0;j<y;j++){
//s=s+a[b][j];
if(max<a[d][j]){
max=a[d][j];
}
}
cout<<\"Max of \"<<d<<\" Row is\"<<max;
cout<<endl;

int e;

cout<<\"Enter a row subscript where we need to find min value \ \";
cin>>e;
cout<<endl;

int min=0;
for(j=0;j<y;j++){
//s=s+a[b][j];
if(min>a[e][j]){
min=a[e][j];
}
}
cout<<\"Min of \"<<e<<\" Row is\"<<min;
cout<<endl;


}

In C++, write a program that creates a two-dimensional array initialized with some integers. Have the following six functions: Total (total of all values in arr
In C++, write a program that creates a two-dimensional array initialized with some integers. Have the following six functions: Total (total of all values in arr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site