Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// find the sum of the elemnts at row= x
- // x is given from the user, should be less than m
- /// find the average of the elements ot column y
- /// where y is given from the user, should be less than n
- #include<iostream>
- using namespace std;
- int main()
- {
- int m,n,i,j,x,y;
- int s=0;
- float avg;
- cout<<"Enter the number of row and columns:\n";
- cin>>m>>n;
- int a[m][n];
- cout<<"Enter the elements of the matrix\n";
- for(i=0;i<m;i++)
- for(j=0;j<n;j++)
- cin>>a[i][j];
- cout<<"Enter number of row and number of column y: \n";
- cin>>x>>y;
- if(x>=m || y>=n)
- {
- cout<<"x shoulde be less than m and y should be less than n";
- return 0;
- }
- for (j=0;j<n;j++)
- s+=a[x][j];
- cout<<"The sum of the elements at row"<<x << " is "<< s;
- int s1=0;
- for(i=0; i<m; i++)
- s1+=a[i][y];
- avg=s1/m;
- cout <<"The average of the elements at column"<<y<<avg;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement