Skip to content

Instantly share code, notes, and snippets.

@michelthomas
Last active August 23, 2019 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelthomas/05b7210fde93e64b5044ead74ffb4e60 to your computer and use it in GitHub Desktop.
Save michelthomas/05b7210fde93e64b5044ead74ffb4e60 to your computer and use it in GitHub Desktop.
C utility functions
void readArray(int length, int array[]) {
int i;
for (i = 0; i < length; i++) {
scanf("%d", &array[i]);
}
}
void printArray(int length, int array[]) {
int i;
for (i = 0; i < length; i++) {
printf("%d ", array[i]);
}
}
void readMatrix(int m, int n, int matrix[][n]) {
int i, j;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
}
}
}
void printMatrix(int m, int n, int matrix[][n]) {
int i, j;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
void copyMatrix(int m, int n, int srcMatrix[][n], int destMatrix[][n]) {
int i, j;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
destMatrix[i][j] = srcMatrix[i][j];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment