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.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
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...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[],...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[], int size); 2. Write a function to generate an array of random integers. void random_array (int arr[], int size, int range); The scale of numbers should be 1 to range. 3. Write a function to find the sum of a sequence of number. int sum (int arr[], int size); 4. Write a function rotate(arr[], d, n) that rotates arr[] of size n by d...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT