0

How to make a simple matrix using nested loops in c++.

Without arrays or using matrix command

3rd Jan 2021, 8:28 PM
Saad Ayyaz
Saad Ayyaz - avatar
6 Antworten
+ 1
A nested loop is fairly straight forward, its how you plan to store and access the data that can be a little challenging. You said ‘without arrays’, have you considered using vectors?
4th Jan 2021, 6:25 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
Then you don’t have to store the values, which makes things much simpler. Since this is a homework assignment I won’t give you the complete answer, but this will get you started: for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { cout << “some number”; } cout << “something else”; } Play around with that a little and you will have the answer. 😊
4th Jan 2021, 6:42 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
Thank you soo much. I will try and complete my code soon. Once again thanks for giving your time and attention. 😊
4th Jan 2021, 6:46 AM
Saad Ayyaz
Saad Ayyaz - avatar
0
No I haven't tried with vectors. As I'm a beginner and I don't know how to use vectors.
4th Jan 2021, 6:27 AM
Saad Ayyaz
Saad Ayyaz - avatar
0
In that case using vectors for a 2D matrix might be a bit advanced. What are the other constraints / expectations if you cannot use arrays?
4th Jan 2021, 6:31 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
0
I was given an assignment in which it said that we have to use nested loops(for,while,do-while) and show the output of 123 456 789
4th Jan 2021, 6:34 AM
Saad Ayyaz
Saad Ayyaz - avatar