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