Question

Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array...

Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array A of integers, declared to be “int** A,” to the standard output. Each of the m rows should appear on a separate line.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>
#include <stdio.h>
using namespace std;

//Function printArra to print elements of array
void printArray(int** A,int m,int n)
{
   //Printing elements of the array
   cout<<"\nThe elements of the array are:"<<endl;
   for (int i = 0; i < m; i++)
   {
       for (int j = 0; j < n; j++)
       {
           cout<<A[i][j]<<" ";
       }
       cout<<endl;
   }
}

int main()
{   //Defining m and n
   int m = 5;
   int n = 6;
   //Declaring array with two dimensions
   //Here m is rows
   int** A = new int*[m];
   //Allocating columns of size n to dynamic array
   for (int i=0; i < m; i++)
       A[i] = new int[n];
      
   //Taking input of elements in array
   cout<<"Enter elements of the array:"<<endl;
   for (int i = 0; i < m; i++)
   {
       for (int j = 0; j < n; j++)
       {
           cin>>A[i][j];
       }
   }
  
   //Calling the function
   printArray(A,m,n);  
}

Code Photo:
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 5 //Function printArra to print elements of array 6 void

Output:
Enter elements of the array: 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 0 The elements of the array are: 1 2 3

Add a comment
Know the answer?
Add Answer to:
Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ercises 61 ly1.9 Write a C++ function printArray(A, m, n) that prints an m × n...

    ercises 61 ly1.9 Write a C++ function printArray(A, m, n) that prints an m × n two- dimensional array A of integers, declared to be "int** A," to the standard output. Each of the m rows should appear on a separate line.

  • Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of...

    Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of integers, declared to be "int** A," to the standard output. Each of the rows should appear on a separate line. Your input will be as follows with the first two values being the number of rows and columns respectively. HINT: This is best done with one for-loop nested within another Sample 1/0 1: Input: 3 2 1 2 3 4 Ол 6 Output: 12...

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.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 pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • Write the definition of a method printArray, which has one parameter, an array of ints. The...

    Write the definition of a method printArray, which has one parameter, an array of ints. The method does not return a value. The method prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.

  • Write a function in C# called show2D. The function should accept a two-dimensional array as an...

    Write a function in C# called show2D. The function should accept a two-dimensional array as an argument and display its contents on the screen. The function should work with any of following arrays: int hours[3][8]; int stamps[5][8]; int cities[14][8];

  • a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a...

    a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT