Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created February 11, 2011 01:28
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 aconbere/821757 to your computer and use it in GitHub Desktop.
Save aconbere/821757 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[]) {
int w;
int h;
int n;
int i;
/* width and height are the first two integers on the stream */
scanf("%d", &w);
scanf("%d", &h);
printf("width: %i\n", w);
printf("height: %i\n", h);
int*array = malloc(w * h * sizeof(int));
for (i = 0; i < w * h; i++) {
scanf("%i", &n);
array[i] = n;
}
print_matrix(array, w, h);
}
int print_matrix(int*array, int w, int h) {
int i;
printf("\n");
for (i = 0; i < w * h; i++) {
if (i && (i % w == 0)) {
printf("\n");
}
printf("%i ", array[i]);
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment