Question

array function
• Create a function called show2D.
• This function should accept a two-dimensional array as parameter and display its contents that are odd numbers on the screen.
• This function should work with any of the following arrays of different sizes:

int hours[3][9];
int stamps[7][9];
int cities[15][9];

• Write a demo program to show how to use the function show2D.

Task 2: Array functions • Create a function called show2D. • This function should accept a two-dimensional array as parameter

this is c++ program

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

I WROTE THE CODE ALONG WITH THE COMMENTS

I AM USING ONE 2D ARRAY { hours[3][9] }

CODE:

#include <iostream>

using namespace std;

//global variables initialization.
int const N=3;
int const M=9;
void show2D(int hours[N][M])
{
//variables declaration.
int i,j;
  
cout<<"\nOdd numbers of the 2D array: ";
for(i =0;i<N;i++) //for loop used to go row wise.
{
for(j=0;j<M;j++) //for loop used to go columns wise.
{
if(hours[i][j]%2!=0) //condition for odd number.
cout<<hours[i][j]<<" ";
}
}
}
int main()
{
  
//variables declaration.
int hours[N][M],i,j;
  
cout<<"Enter 2D Array: "<<endl;
for(i=0;i<N;i++) //input scanning.
{
for(j=0;j<M;j++)
{
cin>>hours[i][j];
}
}
show2D(hours); //calling the show2D() function.

return 0;
}

OUTPUT:

Enter 2D Array: 1 2 3 4 5 6 7 8 9 10 9 11 8 12 7 13 6 14 15 5 16 4 17 3 18 2 19 odd numbers of the 2D array: 1 3 5 7 9 9 11 7

SCREENSHOT OF THE CODE:

л во Р 7 8 #include <iostream> 2 3 using namespace std; 4 5 //global variables initialization. 6 int const N=3; int const M=9

23 int main() 24- { 25 26 //variables declaration. 27 int hours[N][M],i,j; 28 29 cout<<Enter 2D Array: <<endl; 30 for(i=0;i

Add a comment
Know the answer?
Add Answer to:
array function • Create a function called show2D. • This function should accept a 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
  • 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];

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array...

    Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array of Integer and has 2 parameters: arraySize of type int and numberOfDigits of type int. This method should create an array of the specified size that is filled with random numbers. Each random numbers should have the same number of digits as specified in the second parameter In your main method (or additional private methods) do the following: Execute selection sort on quick sort...

  • Create a php program that contains a multi-dimensional array called package. package contains the following arrays:...

    Create a php program that contains a multi-dimensional array called package. package contains the following arrays: colors; which has the values of at least 4 colors sizes; which has the values of at least 4 sizes locations; which has the values of at least 4 locations transport; which has the values of at least 4 types of transport The program should display a random sentence containing one value of, size, color, locations and transport. this is for web 2- php...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • Create a class called Reverse that reverses an array of integers. The class should have two...

    Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) – Which calls the private recursive method, passing the array parameter and which two array elements should be swapped. - private static void reverseRecursive(int [] array, int startIndex, int endIndex) – Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time,...

  • Write a java program that create a 2 dimensional array of type double of size 10...

    Write a java program that create a 2 dimensional array of type double of size 10 by 10. Fill the array with random numbers using a random number generator. Print the array contents. Write a java program that creates a file called data.txt that uses the PrintWriter class. Write the numbers 1 to 42 into the file. Close the file. Attach both files. Thank you in advance

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and...

    C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and the size of the array.as parameters. The function should then create a new array that is the same size as the original array. The function should copy the elements from the first array into the second array in reverse order. So if the initial array is {'a' , 'b', 'c'} then the new array will be {'c', 'b', 'a'} Then in your main(), create...

  • 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...

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