I have a code, which creates an array for at least 4 rows and columns randomly or type from keyboard. Then it calculates a sum of each row an column. The problem is that i don't have any idea how to delete a row and a column which sum is 0.
I wondered maybe a row move to upside and column to the leftside and then create a new array with smaller size and starting with element [1][1] in the previous one.
Here is my code so far:
#include <iostream>
using namespace std;
int i, j;
int main(){
int m, n, sum;
bool answer;
string an;
string y;
do{
cout << "Firstly, could you enter a size of first dimension of an array(at least 4): \n";
cin >> m;}while(m <= 3);
do{
cout << "Firstly, could you enter a size of first dimension of an array(at least 4): \n";
cin >> n;}while(n <= 3);
int array[m][n];
do{
answer = false;
cout << "Select what type of filling the array you want\n";
cout << "If you want to select a filling from keyboard type Y\n";
cout << "If you want to select a random filling type N\n";
cin >> y;
if(y == "Y" || y == "y"){
cout << "*****You chose manual filling*****\n";
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cin >> array[i][j];
}
}
}
else if(y == "N" || y == "n"){
cout << "*****You chose a random filling*****\n";
for(i=0;i<m;i++){
for(j=0;j<n;j++)
array[i][j] = (rand() % (m+n) - ((m+n)/2));
}
cout << endl;
}
else{
cout << "You didn't choose a type!\n";
cout << "Do you want to continue? Type Y, if you want: \n";
cin >> an;
if(an == "Y" || an == "y") answer = true;
}
}while(answer);
cout << "Here is your array: \n";
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cout << array[i][j] << "\t";}
cout<<endl;
}
for(i=0;i<m;i++){
sum = 0;
for(j=0;j<n;j++){
sum += array[i][j];
}
cout << "Sum of elements of Row " << i+1 << ": " << sum << endl;}
for(i=0;i<n;i++){
sum = 0;
for(j=0;j<m;j++){
sum += array[j][i];
}
cout << "Sum of elements of Column " << i+1 << ": " << sum << endl;
}
}