C++ part 7 (1/2) – Multidimensional arrays

Here is the code for the multidimensional array with picture of the output and paint demonstration where I used excel cells to show the logic of the array. Again, nothing stops you from using strings or any other datatypes or functions with arrays. You can apply everything from previous posts in this section.

#include <iostream>
using namespace std;
int main()
{
                int numbers [10][5] = { {1, 2, 3, 4, 5}, // Row 0 of 9
                                        {6, 7, 8, 9, 10}, // Row 1 of 9
                                        {11, 12, 13, 14, 15},
                                        {16, 17, 18, 19, 20},
                                        {21, 22, 23, 24, 25},
                                        {26, 27, 28, 29, 30},
                                        {31, 32, 33, 34, 35},
                                        {36, 37, 38, 39, 40},
                                        {41, 42, 43, 44, 45},
                                        {46, 47, 48, 49, 50},
                                        };
                             
                for(int i = 0; i < 10; i++) {
                        for(int b = 0; b < 5; b++) {
                                 cout << numbers[i][b] << endl;
                        }
                }
                
                system(“PAUSE”);
                return 0;
}

Here is the output:

1

Here is the pain demonstration:

2

Here is a silly summation code to demonstrate that if the syntax is right you can basically apply everything in programming languages:

#include <iostream>
using namespace std;
int main()
{
                int numbers [10][5] = { {1, 2, 3, 4, 5}, // Row 0 of 9
                                        {6, 7, 8, 9, 10}, // Row 1 of 9
                                        {11, 12, 13, 14, 15},
                                        {16, 17, 18, 19, 20},
                                        {21, 22, 23, 24, 25},
                                        {26, 27, 28, 29, 30},
                                        {31, 32, 33, 34, 35},
                                        {36, 37, 38, 39, 40},
                                        {41, 42, 43, 44, 45},
                                        {46, 47, 48, 49, 50},
                                        };
                             
                for(int i = 0; i < 10; i++) {
                        for(int b = 0; b < 5; b++) {
                                 cout << numbers[i][b] << endl;
                                 numbers[i][b] +=  numbers[i][b];
                        }
                }
                
                                             
                for(int i = 0; i < 10; i++) {
                        for(int b = 0; b < 5; b++) {
                                 cout << numbers[i][b] << endl;
                        }
                }
                
                system(“PAUSE”);
                return 0;
}

Output where it basically continues from the previous 50:

1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s