C++Tutorial for Beginners 21 - Multidimensional Arrays

preview_player
Показать описание
-------------------------------------------------------------------------------------------------------------------------------------------
We can use multidimensional array in C++ to represent tables (2D arrays), or even cubes of data (3D array) -- or, less commonly, even unvisualisable 4- or 5- dimensional structures.
--------------------------------------------------------------------------------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

Just wanna say that the challenge you left at the end was definitely a "challenge". For whatever reason my mind couldn't wrap around how to initialize the array through a nested for loop, but I tried for a while and watched some other videos and it took me quite a bit of time but I'm glad that I did. Now it seems (mostly) simple.

Anyways, thanks for the videos so far, they're great.

dovekie
Автор

for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
mult_table[i][j] = (i+1)*(j+1);
cout << mult_table[i][j] << " ";
}
cout << endl;
}

this makes the multiplication table. I defined mult_table above this as int mult_table[10][10];

zman
Автор

This code creates a perfectly squared table and in a pretty good runtime...


#include <iostream>

using namespace std;

int main()
{
int table [10][10];
for (int c=0;c<10;c++){
for (int r=0;r<10;r++){
table [r][c]= (r+1)*(c+1);
if (table[r][c]/10 >= 1){
cout << table [r][c] << " " << flush;
}
else{
cout << table [r][c] << " " << flush;
}
}
cout << endl;
}
return 0;
}

pietroehrlich
Автор

Thank you for this Tutorials! It's really easy to understand when you're explaining it. Salute to you sir, and Good job!

christiangerarddelosreyes
Автор

Started this playlist a while ago. (like back in 2015) ... now i need to finish this in 2021. breaking habit of not finishing what i started cause it cost me a lot of money and wasted time

drwblkfact
Автор

Just signed up on your website.Waiting for the Advanced course on C++, thanks for the free resource on YouTube.

plemyk
Автор

I appreciate this course very much, but I also hope the teacher recommends an introductory book on C++...

andyhsu
Автор

code for multiplication table:

#include <iostream>
using namespace std;

int main() {
int array[10]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

for(int i=0; i<10;i++) {
for(int j=0; j<10; j++) {
cout<<array[i]<<" * "<<array[j]<<" = "<<array[i]*array[j]<<endl;
}
cout<<endl;
}
return 0;
}

anunaysharma
Автор

Ah I still trying to understand this concept let alone a challenge but alright I will try lol. Speaking of which I want to ask once more. We should always put }; right? Cause sometimes I c u just put } n then that's it.

tokugeeky
Автор

Here is the code that i made as a conference

#include<iostream>
using namespace std;

int main() {

int array[10][10];

for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
array[i][j] = (i + 1) * (j + 1);
cout << array[i][j];
}
cout << endl;

}

return 0;
}

yangyangyang
Автор

Hi John i am learning c++ with your tutorials ! thank you so much !

I have a question with this tutorial 

if you look at 3:50 of this video. you wrote :

string animals[2][3] =
{
{"fox ", "dog ", "cat"},
{"mouse ", "squirrel ", "parrot "}
};

i cant understand why you put 2 instead of 3, each bracket contain 3 objects/
But you explained that this number has to be the exactly same as the number of objects that bracket contains.
It actually works fine on my compiler (Visual Studio 2013) either with 2 or 3, it shows every object brackets contain but i would like to know if i misunderstood something here or if it was a simple mistake from you.

kazz
Автор

I always get an error when I try to run this:
int mainProcess(int me, int my) {
string array1[7][3] = {
{"A", "B", "C"},
{"D", "E", "F"},
{"G", "H", "I"},
{"J", "K", "L"},
{"M", "N", "O"},
{"P", "Q", "R"},
{"S", "T", "U"}
};
cout << array1[my][me] << endl;
return 0;
}

This code is a self made function. "my" is supplied with any no from 1 to 7 and "me" is a random number made from srand(time(0)) and 1+rand()%3.
Would you kindly point out the error here, sir?
P.S. I'm still learning C++.

wakuwaku
Автор

Guys, hel. When I run this code on any IDE (Visual Basic, Eclipse or even CPPdroid) it stops working.. Any fix please?

PaulBlxck
Автор

sir upload videos on abstraction, pure virtual funcions, dynamic constructors, .

saksham
Автор

This is for a perfectly square table, except the hundred.

int table[10][10];

for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
table[i][j] = (i + 1) * (j + 1);
std::cout << table[i][j] << std::flush;
if ((i + 1) * (j + 1) < 9 || (i + 1) * (j + 1) == 9)
{
std::cout << " " << std::flush;
}
else
{
std::cout << " " << std::flush;
}
}
printf("\n");

}

vinnievincent
Автор

long int multiplication[3][10] = {
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{2, 6, 8, 10, 12, 14, 16, 18, 20},
{3, 6, 9, 12, 15, 18, 21, 24, 27, 20}


};
for (int i = 0; i < 3; i++) {
for (int j = 0; i < 10; i++) {
cout << multiplication[i][j]<< " "<< flush;
}
}
system("pause");
}

whats wrong with my code it keeps giving me random

mustafaal-obeid
Автор

int multi_Table[10][10];

for (int i = 1; i < 11; i++)
{
for (int j = 1; j < 11; j++)
{
multi_Table[i - 1][j - 1] = i * j;
}

}

for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
cout << multi_Table[i][j] << "\t " << flush;
}
cout << endl;
}

It created the multiplication table, The only minor issue is that there is a gap between the first and second column. I don't know how to fix that. If I take out the tab character, all the numbers are mushed together with no space in between.

TheMASTERFURIOUS
Автор

int main()
{

int table[11][11];

for(int i = 1 ; i <= 10 ; i++ ){
for(int j = 1 ; j <= 10 ; j ++ ){
table[i][j] = i * j;
}
}



for(int i = 1; i <= 10 ; i++ ){
for(int j = 1 ; j <= 10 ; j ++ ){
cout << table[i][j] << "\t" << flush;
}

cout << endl;
}

return 0;
}

/* when I set the array at [10][10], I get an error message saying
*** stack smashing detected ***
*** not sure what that's all about???
*/

MrSaxonHall
Автор

##include <iostream>
using namespace std;

int main() {
    int array[10][10];

    for (int i = 1; i < 11; i++) {
        for (int j = 1; j < 11; j++) {
            array[i-1][j-1] = i * j;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
             cout << " " << array[i][j] << " " << flush;
        }
        cout << endl;
    }
    return 0;
}

I made that piece of code :) And your videos are amazing!!! I am argentinian and I understand you fine... thanks!!! You have a great accent and pronounciation!!!

Sorry if I have some mistakes writing some words I am not that good speaking english. Thanks again!!!

ignabelitzky
Автор

console started making beeping noises and console froze had to close it lol... then i figured out im dumb

SpyWhaleSGT
welcome to shbcf.ru