Question

Hello I need some help with creating a function in c++ It has to be an...

Hello I need some help with creating a function in c++

It has to be an Two-Dimensional array put in a function

and it basically should output 20 rows and 20 columns

if anyone can provide explanation it would be great

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

void generate_2d() {
    int arr[20][20];    // generate a 2D array
    for (int i = 0; i < 20; ++i) {  // go through all rows
        for (int j = 0; j < 20; ++j) {  // go through all columns of each row
            arr[i][j] = i * j;    // storing some value in each array element
        }
    }
    // Now, let's print the array
    for (int i = 0; i < 20; ++i) {  // go through all rows
        for (int j = 0; j < 20; ++j) {  // go through all columns of each row
            cout << arr[i][j] << "\t";   // print the element
        }
        cout << endl;   // print a newline after each row
    }
}

int main() {
    generate_2d();
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Hello I need some help with creating a function in c++ It has to be an...
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