Advertisement
Guest User

Untitled

a guest
May 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. /// find the sum of the elemnts at row= x
  2. // x is given from the user, should be less than m
  3. /// find the average of the elements ot column y
  4. /// where y is given from the user, should be less than n
  5.  
  6. #include<iostream>
  7. using namespace std;
  8. int main()
  9. {
  10. int m,n,i,j,x,y;
  11. int s=0;
  12. float avg;
  13. cout<<"Enter the number of row and columns:\n";
  14. cin>>m>>n;
  15.  
  16. int a[m][n];
  17. cout<<"Enter the elements of the matrix\n";
  18.  
  19. for(i=0;i<m;i++)
  20. for(j=0;j<n;j++)
  21. cin>>a[i][j];
  22.  
  23. cout<<"Enter number of row and number of column y: \n";
  24. cin>>x>>y;
  25.  
  26.  
  27. if(x>=m || y>=n)
  28. {
  29. cout<<"x shoulde be less than m and y should be less than n";
  30. return 0;
  31. }
  32.  
  33. for (j=0;j<n;j++)
  34. s+=a[x][j];
  35.  
  36. cout<<"The sum of the elements at row"<<x << " is "<< s;
  37.  
  38. int s1=0;
  39. for(i=0; i<m; i++)
  40. s1+=a[i][y];
  41.  
  42. avg=s1/m;
  43. cout <<"The average of the elements at column"<<y<<avg;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement