#include <stdio.h>
#include <stdlib.h>

int * generateArray(int * width, int * height);
void printArray(int * array, int rows, int columns);


int main(void){
	
	int * width = malloc(sizeof(int));
	int * height = malloc(sizeof(int));

	int * generatedArray = generateArray(width,height);
	printArray(generatedArray, *width, *height);

	free(generatedArray);
	free (width);
	free(height);
	
}

int * generateArray(int * width, int * height){
        printf("Please enter the width and height, separated by spaces: ");
        scanf("%d %d",width, height);
        
        int * array = malloc(sizeof(int) * (*width) * (*height));
   
        int r, c;       
        srand(time(NULL));
        
        for (r = 0; r < *height; r++){
                for (c = 0; c < *width; c++){
                        *(array + (r * (*width)) + c) = rand();
                }
        }
	return array;
}



void printArray(int * array, int rows, int columns){
	int r, c;
	for (r = 0; r < rows; r++){
		for (c = 0; c < columns; c++){
			printf("%d \t",array[r * columns + c]);
		}
		printf("\n");
	}
	
}
