Question: Could someone please help with this C program? 3.Print Matrix Trying to have a 2D array parameter in a function in C isn't as simple
Could someone please help with this C program?
3.Print Matrix Trying to have a 2D array parameter in a function in C isn't as simple as in Java. Like with single dimensional arrays, it's common to actually make the parameter a pointer to a pointer type rather than an actual array type. Create a function to print a 2D array of characters. Write a program that asks the user for a height and width and dynamically allocates a 2D array of those dimensions. Fill the array with dots and then randomly put asterisks in some elements. For the number of asterisks, it should be 10% of the width times the height cast to an int (for example, 10 * 10 * 0.1 = 10). Then, use the print function on the array. Here's the function header to get you started: void print_matrix(char ** matrix, int height, int width) Sample Run: Enter Height: 10 Enter Width: 10 Asterisk Count: 10 array (0x7f939d600000): . . . * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * . . . . . . . . . * . . . * . . . . . . . . . . . . . * . . . * . . . . . . . . . . . * . * . . * . . . . * . . . . . . . . . . . .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
