Question

In: Computer Science

Write a function that dynamically allocates references to other arrays. The goal is to end up...

Write a function that dynamically allocates references to other arrays. The goal is to end up with a square 2D array who's value increment with each index increment so that the values placed in first array start at zero and end at 9, and the values placed in the last array start at 90 and end at 99.

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

code.cpp

#include <iostream>
using namespace std;

int main()
{
   int **arrays;
   arrays = new int*[10];
   for(int i=0;i<10;i++){
       arrays[i] = new int[10];
   }

   int counter=0;
   for(int i=0;i<10;i++){
       for(int j=0;j<10;j++){
           arrays[i][j] = counter;
           counter++;
       }
   }


   cout<<"Content of the array is "<<endl;
   for(int i=0;i<10;i++){
       for(int j=0;j<10;j++){
           cout<<arrays[i][j]<<" ";
       }
       cout<<endl;
   }


   return 0;
}

output


Related Solutions

In C++ Write a program that dynamically allocates a built-in array large enough to hold a...
In C++ Write a program that dynamically allocates a built-in array large enough to hold a user-defined number of test scores. (Ask the user how many grades will be entered and use a dynamic array to store the numbers.) Once all the scores are entered, the array should be passed to a function that calculates the average score. The program should display the scores and average. Use pointer notation rather than array notation whenever possible. (Input Validation: Do not accept...
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function...
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function must not be void and must output type int* i.e. it must take the form: int* merge_sort(int a[], int n) where a[ ] is the input matrix and n is the size of the matrix. You may use an auxiliary functions such as "merge." The returned array should be sorted using merge_sort and should not modify the array that was input (a[ ] ).
In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
CONSUMER LAW ( please write the references of detail at the end ) TOPIC - CONSUMER...
CONSUMER LAW ( please write the references of detail at the end ) TOPIC - CONSUMER GUARANTEES – Schedule 2 of the Competition and Consumer Act 2010 (Cth) (“the ACL”) Provide the relevant sections of the ACL and give case examples (where applicable) to support your answers.
CONSUMER LAW ( please write the references of detail at the end ) CONSUMER GUARANTEES –...
CONSUMER LAW ( please write the references of detail at the end ) CONSUMER GUARANTEES – Schedule 2 of the Competition and Consumer Act 2010 (Cth) (“the ACL”) Explain the rule that goods must be reasonably fit for any disclosed purpose. Can the consumer guarantees be excluded under the ACL?
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
In C++ Write a function that accepts two int arrays of the same size. The first...
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. THE FUNCTION SHOULD FIND ALL NUMBERS IN THE ARRAY THAT ARE GREATER THAN OR EQUAL TO THE AVERAGE. You need to design the function. so the output code should be: (show contents of 1st array) The numbers that are greater than the average of the first array are: (the...
In c++ Array expander Write a function that accepts an int array and the arrays size...
In c++ Array expander Write a function that accepts an int array and the arrays size as arguments. The function should create a new array that is twice the size of the argument array. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays of integers. Neither list contains duplicates, and the resulting list should not contain duplicates either. Hint: You may want to call a helper function from merge. PROGRAM: C
Write a function called is_valid_phone_number matches that takes two int arrays and their respective sizes, and...
Write a function called is_valid_phone_number matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5. in C++ with explanations
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT