Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[]) {
- int w;
- int h;
- int n;
- int i;
- int* array;
- /* 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);
- array = malloc(w * h * sizeof(int));
- read_matrix(&array, w * h);
- print_matrix(&array, w, h);
- }
- void read_matrix(int* array, int length) {
- int n;
- int i;
- for (i = 0; i < length; i++) {
- scanf("%i", &n);
- array[i] = n;
- }
- }
- 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");
- }
Add Comment
Please, Sign In to add comment