Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Array2D.c #include #include void printArray(int**, int); int main() { int i = 0, j = 0, n = 5; int **arr = (int**)malloc(n * sizeof(int*));

image text in transcribed

Array2D.c

#include #include void printArray(int**, int); int main() { int i = 0, j = 0, n = 5; int **arr = (int**)malloc(n * sizeof(int*)); // (3) Add your code to complete allocating and initializing the 2-D array here. The content should be all 0. // This will print out your array printArray(arr, n); // (6) Add your code to make arr a diagonal matrix // (7) Call printArray to print array return 0; } void printArray(int ** array, int size) { // (5) Implement your printArr here: }

Please answer all questions, thanks!

1. Open Array2D. (below). This program will create anxn array of int. Explain what line \#8 does. 2. Since every array , ust be allocated in the memory before it can be used, we need to allocate the rows one by one. To do this, we need to be able to access the pointers from the first array (pointed by arr). Assuming i is the index of that array, how do we access the ith value of the array? 3. Without using array notation ([]), insert code to complete allocating all the rows and initialize all contents to be zero. Your code should work with different values of n. Hint: If j is the index of each row, how do you access arr[i][j] in pointer notation? 4. To verify whether you have created your array correctly, we need a function to print out the array. The function printArray has been declared. It takes in both the array to be printed and the size of the array. Why do we need to pass the size as an argument? 5. Complete printArray so it prints out the content and layout of an array correctly. 6. Now, let us modify the content of the array. Insert code to make the array into a diagonal matrix that looks like the one below (do not limit the size to 5). 1000002000003000004000005 Make sure your code only prints this array out, not the one with all zeros as before

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions