This document contains the source code for a C++ program that computes the sum of rows and columns in a two-dimensional array. The program prompts the user to enter the number of columns and rows. It then prompts the user to enter a number for each element of the array. The program uses nested for loops to calculate the sum of each column and stores it in a column array. It also calculates the sum of each row and stores it in a row array. Finally, it displays the original 2D array along with the column sums and row sums.
This document contains the source code for a C++ program that computes the sum of rows and columns in a two-dimensional array. The program prompts the user to enter the number of columns and rows. It then prompts the user to enter a number for each element of the array. The program uses nested for loops to calculate the sum of each column and stores it in a column array. It also calculates the sum of each row and stores it in a row array. Finally, it displays the original 2D array along with the column sums and row sums.
This document contains the source code for a C++ program that computes the sum of rows and columns in a two-dimensional array. The program prompts the user to enter the number of columns and rows. It then prompts the user to enter a number for each element of the array. The program uses nested for loops to calculate the sum of each column and stores it in a column array. It also calculates the sum of each row and stores it in a row array. Finally, it displays the original 2D array along with the column sums and row sums.
Program ming In CS 103 Rosny Angelo M. Lanuza Kurt Jayson SUBMITTED BY Macapagal Julius Z. Punay Mark Nartea Bernie A. Baltazar
SUBMITTED TO Cathie De Salit Dumpit
//Program Using 2D arrays that Computes the Sum of Rows
and Column #include<iostream> using namespace std; int main() { int arr[50][50],column[50]={0},row[50]={0}; int sizec,sizer,rc,total,Number=0; cout<<"How many Column you want: "; cin>>sizec; cout<<"How many Rows you want: "; cin>>sizer; //Link Start total=sizec*sizer;// total of Number input cout<<"Please Enter "<<total<<" Number"; for(int c=0;c<sizec;c++) { for(int r=0;r<sizer;r++) { cout<<"\nEnter Number "<<++Number<<":"; // Storing the Num into Array cin>>arr[c][r]; } } //-----Looping of Column for(int c=0;c<sizec;c++) { for(int r=0;r<sizer;r++) {
column[c]=column[c]+arr[c][r]; //Getting the sum of
Column } } //----Display the all value of Array for(int c=0;c<sizec;c++) { for(int r=0;r<sizer;r++) { cout<<"\t"<<arr[c][r]; } cout<<"\t"<<"="<<" "<<column[c]<<"\n"; } //----Looping in Rows for(int c=0;c<sizec;c++) { for(int r=0;r<sizer;r++) { row[r]=row[r]+arr[c][r]; //Getting the sum of Row } } //----Displaying of line cout<<" "; for(int r=0;r<sizer;r++){ cout<<"_______"; } cout<<"\n"; for(int r=0;r<sizer;r++) { cout<<"\t"<<row[r]; } }