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.
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:
Output:
Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array...
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 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 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 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 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. 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 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 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 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 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...