#2d array multiplication table

1 messages · Page 1 of 1 (latest)

steel tinsel
#

Im having trouble on how i can code the desire output in the picture

lime joltBOT
#

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.

steel tinsel
#

I want to know what tips i can use to do it

tough vortex
#

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.

steel tinsel
#

its ok thank you

lime joltBOT
#

@steel tinsel Has your question been resolved? If so, type !solved :)

silent wren
#

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.

tough vortex
#

The array is dynamically sized though since the dimensions are read in at runtime.

silent wren
#

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.

tough vortex
#

What size do you propose then? Make it 10x10 and call it good enough?

silent wren
#

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.

modest forum
silent wren
modest forum
# silent wren *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

hollow pulsar
#

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.