Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7. unsigned int arrh, arrw, arrwsum=0, arrhsum=0, sumall=0;
  8. cout<<"Input the height of your array: ";
  9. cin>> arrh;
  10. cout<<"Input the width of your array: ";
  11. cin>> arrw;
  12. int work[arrh][arrw];
  13. //This takes care of going to a new row once j=arrw
  14. for(int i=0;i<arrh;i++)
  15. {
  16. //Input for each row, individually
  17. for(int j=0;j<arrw;j++)
  18. {
  19. work[i][j]=rand()%255;
  20. sumall+=work[i][j];
  21. }
  22. }
  23. cout<<endl;
  24. //Outputting the array in a 2D environment
  25. for(int i=0;i<arrh;i++)
  26. {
  27. for(int j=0;j<arrw;j++)
  28. {
  29. cout<<setw(10)<<work[i][j];
  30. }
  31. cout<<endl;
  32. }
  33. cout<<endl;
  34. //Output for row sum
  35. for(int i=0;i<arrh;i++)
  36. {
  37. for(int j=0;j<arrw;j++)
  38. {
  39. arrwsum+=work[i][j];
  40. }
  41. cout<<"The sum of row "<<i+1<<" is: "<<arrwsum<<endl;
  42. arrwsum=0;
  43. }
  44. cout<<endl;
  45. //Output for column sum
  46. for(int i=0; i<arrw; i++)
  47. {
  48. for(int j=0; j<arrh; j++)
  49. {
  50. arrhsum+=work[j][i];
  51. }
  52. cout<<"The sum of column "<<i+1<<" is: "<<arrhsum<<endl;
  53. arrhsum=0;
  54. }
  55. cout<<endl;
  56. cout<<"Sum of all numbers: "<<sumall<<endl;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement