Skip to content

Instantly share code, notes, and snippets.

@fenske
Created December 4, 2019 19:02
Show Gist options
  • Select an option

  • Save fenske/0c5dc17ee02ea89b90ecf0eb631c49ca to your computer and use it in GitHub Desktop.

Select an option

Save fenske/0c5dc17ee02ea89b90ecf0eb631c49ca to your computer and use it in GitHub Desktop.

Revisions

  1. fenske created this gist Dec 4, 2019.
    36 changes: 36 additions & 0 deletions PositionalArray.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #include <iostream>

    using namespace std;

    #define N 4

    void f(int A[N][N], int B[N]);

    int main() {
    int A[N][N] = {
    {1, 2, 3, 4},
    {1, 2, 3, 4},
    {1, 2, 3, 4},
    {0, 2, 0, 4}
    };
    int B[N] = {1, 1, 1, 1};


    f(A, B);

    for (int i = 0; i < N; i++) {
    cout << B[i] << " ";
    }

    }

    void f(int A[N][N], int B[N]) {
    for (int j = 0; j < N; j++) {
    for (int i = 0; i < N; i++) {
    if (A[i][j] == 0) {
    B[j] = 0;
    break;
    }
    }
    }
    }