#2d array multiplication table
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
I want to know what tips i can use to do it
One tip is that you don't need a 2d array or any array for that matter.
Just make 2 nested for-loops and print the numbers.
Though I suppose the assignment directly asks you to do it anyway, so I guess you have to.
2d arrays are a pain in C++. Your options are to make a 1d array with n*m dimensions and calculate the index or make a 1d array of pointers with size n and assigne each pointer a 1d array of numbers of size m. Both ways suck.
You can make your life a little easier by using std::vector, but you're probably not allowed to.
Sorry that none of my "tips" are very helpful.
its ok thank you
@steel tinsel Has your question been resolved? If so, type !solved :)
Isn't a 2d array like int arr [1][1] (a matrix)?
If so, he can do int arr [R][C] in which R and C are the row and column indexes. It doesn't seem like he needs to automatically fill the matrix, just type each number. So he can add a user input inside 2 nested for-loops and then print the matrix once done.
The array is dynamically sized though since the dimensions are read in at runtime.
Yeah, they are.. but I don't expect this exercise to be concerned with this (since it's for a beginner). Of course, if we are to be real technical here, can't argue against what you proposed.
What size do you propose then? Make it 10x10 and call it good enough?
Humn, oh well, can't get simpler than that I suppose. I completely forgot that dynamic arrs are not standard, neither in C nor in C++, my bad.
our C lecturer just slapped a fat int arr[100][100] and then had us take the required dimensions from the user lol.
old problems require lazy solutions /s
yeah that way there's no null pointers and stuff! problem solved! /s. though later he just brushed through pointers without ever teaching what malloc and free do, dangling pointers etc because not important enough for exams, just write this stuff ez marks
The value is always (row+1)*(col+1), so you can do this without any arrays or loops, but you should use the array anyway if this is for homework.