Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- unsigned int arrh, arrw, arrwsum=0, arrhsum=0, sumall=0;
- cout<<"Input the height of your array: ";
- cin>> arrh;
- cout<<"Input the width of your array: ";
- cin>> arrw;
- int work[arrh][arrw];
- //This takes care of going to a new row once j=arrw
- for(int i=0;i<arrh;i++)
- {
- //Input for each row, individually
- for(int j=0;j<arrw;j++)
- {
- work[i][j]=rand()%255;
- sumall+=work[i][j];
- }
- }
- cout<<endl;
- //Outputting the array in a 2D environment
- for(int i=0;i<arrh;i++)
- {
- for(int j=0;j<arrw;j++)
- {
- cout<<setw(10)<<work[i][j];
- }
- cout<<endl;
- }
- cout<<endl;
- //Output for row sum
- for(int i=0;i<arrh;i++)
- {
- for(int j=0;j<arrw;j++)
- {
- arrwsum+=work[i][j];
- }
- cout<<"The sum of row "<<i+1<<" is: "<<arrwsum<<endl;
- arrwsum=0;
- }
- cout<<endl;
- //Output for column sum
- for(int i=0; i<arrw; i++)
- {
- for(int j=0; j<arrh; j++)
- {
- arrhsum+=work[j][i];
- }
- cout<<"The sum of column "<<i+1<<" is: "<<arrhsum<<endl;
- arrhsum=0;
- }
- cout<<endl;
- cout<<"Sum of all numbers: "<<sumall<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement