Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code: #include #include void printArray( int **, int ); int main() { int i = 0, j = 0, n = 5; int **arr =
Code:
#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 our your array
printArray(arr, n);
// (6) Add your code to make arr a diagonal matrix
// (7) All printArray to print array
printArray(arr, n);
return 0;
}
void printArray(int ** array, int size){
// (5) Implement your printArr here:
}
1. Open Array2D.c. This program will create a n x n array of int. Explain what line #8 does. 2. Since every array must 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 notations ([]), Insert code to complete allocating all the rows and initialize all contents to be 0. You code should work with different values for n. Hint: if j is the index of each row, how do you access arr[iJi 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 size of 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's modify the content of the array. Insert code to make the array into a diagonal matrix that looks like this (again, do not limit the size to 5 only): 0 2 0 0 0 0 0 0 0 0 4 0 0 0 0 7. Call printArray to print out your new array and verify resultStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started