Question

Write loop(s) that print ALL the content of the following 2D array #include <iostream> using namespace...

Write loop(s) that print ALL the content of the following 2D array

#include <iostream>

using namespace std;


int main(){
  
int rows;
int cols;
int offset;
cin >> rows;
cin >> cols;
cin >> offset;
  
int** arr = new int*[rows];
for(int i = 0; i < rows; ++i)
arr[i] = new int[cols];
  
for(int i = 0; i < rows; i++) // initialization
for(int j = 0; j < cols; j++)
arr[i][j] = offset + i;
  
// printing, your code goes here
  
return 0;
}

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

#include <iostream>
using namespace std;

int main()
{

int rows;
int cols;
int offset;
cin >> rows;
cin >> cols;
cin >> offset;

int** arr = new int*[rows];
for(int i = 0; i < rows; ++i)
arr[i] = new int[cols];

for(int i = 0; i < rows; i++) // initialization
for(int j = 0; j < cols; j++)
arr[i][j] = offset + i;

//Print the contents of array
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
      cout<<arr[i][j]<<"\t";
}
    cout<<endl;
}


return 0;
}

Output

n no

Add a comment
Know the answer?
Add Answer to:
Write loop(s) that print ALL the content of the following 2D array #include <iostream> using namespace...
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