Last active
November 28, 2023 07:21
-
-
Save juanfal/39f82dd47d7b5c9d9eff98c2dff8b11e to your computer and use it in GitHub Desktop.
building an identity matrix
This file contains 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
// t13e03.identityMat.cpp | |
// juanfc 2023-11-23 | |
// | |
#include <iostream> | |
#include <array> | |
using namespace std; | |
const int N = 3; | |
typedef array<array<int, N>,N> TSqMat; | |
void print(TSqMat m); | |
TSqMat identMat(); | |
int main() | |
{ | |
print(identMat()); | |
return 0; | |
} | |
TSqMat identMat() | |
{ | |
TSqMat m; | |
for (int row = 0; row < N; ++row) | |
for (int col = 0; col < N; ++col) | |
m[row][col] = (row==col)? 1: 0; | |
return m; | |
} | |
void print(TSqMat m) | |
{ | |
for (int row = 0; row < N; ++row) { | |
for (int col = 0; col < N; ++col) { | |
cout << m[row][col] << " "; | |
} | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment