DasShelmer

8.3.19

Dec 3rd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. static int li = -1, lj = -1;// lenght
  6. void setZero(int** arr, int &i, int &j) {
  7.     if (i >= li || j >= lj)
  8.         return;
  9.     if (arr[i][j] % 2 == 0)
  10.         arr[i][j] = 0;
  11.     if (j == lj - 1) {
  12.         j = 0;
  13.         i++;
  14.     }
  15.     else
  16.     {
  17.         j++;
  18.     }
  19.     setZero(arr, i, j);
  20. }
  21.  
  22. int main() {
  23.     while (li < 1 || lj < 1) {
  24.         cout << "Enter the row and collum count: ";
  25.         cin >> li >> lj;
  26.     }
  27.     cout << "Enter the array: " << endl;
  28.     int iD = 0, jD = 0;
  29.     int** arr = new int* [li];
  30.     for (int i = 0; i < li; i++) {
  31.         arr[i] = new int[lj];
  32.         for (int j = 0; j < lj; j++) {
  33.             cin >> arr[i][j];
  34.         }
  35.     }
  36.  
  37.     setZero(arr, iD, jD);
  38.     cout << "Result array: " << endl;
  39.     for (int i = 0; i < li; i++) {
  40.         for (int j = 0; j < lj; j++) {
  41.             cout << arr[i][j] << " ";
  42.         }
  43.         cout << endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment