8/Write a program that asks the user to enter integer numbers and store the numbers in a two dimensional array, then replace any 9 digit by 0 digit. After that replace the numbers with the odd summations indices by the even summation indices.
using while, for and array if possible
1
Expert's answer
2017-12-06T07:13:25-0500
#include <iostream> #include <stdlib.h> #include <string> using namespace std;
void print(string** Matrix, int n, int m) { for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) cout << Matrix[i][j] << " "; cout << "\n"; } }
void ninesToZiros(string** Matrix, int n, int m) { int k = 0, strn = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { k = 0; strn = Matrix[i][j].length(); while(k < strn) { if(Matrix[i][j][k] == '9') { if(k == 0 && strn != 1) { Matrix[i][j].erase(0, 1); --strn; --k; } else { Matrix[i][j][k] = '0'; } }
++k; } } }
}
void oddByEven(string** Matrix, int n, int m) { int oddi = -1, oddj = -1, eveni = -1, evenj = -1;
Comments