Last active
November 21, 2016 00:57
-
-
Save AaronGoldsmith/484c18cfb0637a18d1ec344090514fb7 to your computer and use it in GitHub Desktop.
matrix structure in c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Matrix{ | |
// you cannot initialize a variable .... | |
// ... (assign it values) inside the structure | |
int matrix[3][3]; | |
}; | |
void printMatrix(struct Matrix *m){ | |
for (int i = 0;i<3;i++){ | |
for(int j = 0; j<3; j++){ | |
// you have to print out from m[][] | |
// m is of type Matrix | |
cout << m[i][j] << " "; | |
} | |
cout<<endl; | |
} | |
} | |
void main(String args[]){ | |
// initialize the matrix in main() | |
struct Matrix X = { {3,2,1}, {1,2,1}, {1,1,1} }; | |
// then pass in the initialized matrix into printMatrix() | |
printMatrix(X); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment