-
-
Save haldun/9587640 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
void Identity(int *matrix, size_t size) | |
{ | |
for (size_t i = 0; i < size; ++i) { | |
for (size_t j = 0; j < size; ++j) { | |
matrix[i * size + j] = (i == j) ? 1 : 0; | |
} | |
} | |
} | |
void PrintMatrix(int *matrix, size_t size) | |
{ | |
for (size_t i = 0; i < size; ++i) { | |
for (size_t j = 0; j < size; ++j) { | |
printf("%d", matrix[i * size + j]); | |
} | |
printf("\n"); | |
} | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
size_t size = 0; | |
printf("Size of matrix: "); | |
scanf("%zd", &size); | |
int matrix[size][size]; | |
Identity(&matrix[0][0], size); | |
PrintMatrix(&matrix[0][0], size); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment