Arrays in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Arrays in c++

hey everyone! i want to obtain multiplication with multi-dimensional arrays but i dont know the problem. my output is "1" with my code. can anybody help! #include<iostream> using namespace std; int main() { int a[10][10]; int j=1, i=1; while (j < 10) { a[i][j] = i * j; if (i <= 10) i++; else { j++; i = 1; } } i=1, j=1; while (i <= 10) { if(j <= 10) { cout << a[i][j] << "\t"; j++; } else { cout << "\n"; j=1; i++; } return 0; } }

7th Jun 2017, 7:45 AM
arian
13 Answers
+ 1
Your code is below. What I don't understand is why you need Array. https://code.sololearn.com/cHr4P2xH7fRN/?ref=app
7th Jun 2017, 10:32 AM
Milind
Milind - avatar
+ 2
What do you want to happen?
7th Jun 2017, 9:14 AM
Maart
Maart - avatar
+ 1
In the else loop, you set i=1; again, that's not needed. Then after the entire while loop you set both i and j to 1. (i=1, j=1) So whatever i and j were being set to in the loop, they are 1 again after. And 1*1=1, so your output is 1.
7th Jun 2017, 7:49 AM
Maart
Maart - avatar
+ 1
Can you make the code public and share the link? That way it's easier to check
7th Jun 2017, 8:06 AM
Maart
Maart - avatar
+ 1
I actually meant a link tothe Playground like this, but this worked too. I changed up some things. Removed the line i+1, j=1; after your while loop. Just look at your and my code for all the differences. It now returns the product of the last incremented i and j https://code.sololearn.com/cLvEwJR25wd3/?ref=app
7th Jun 2017, 8:29 AM
Maart
Maart - avatar
+ 1
thanks bro thats what i wanted i use array just for better understanding and practice
7th Jun 2017, 10:47 AM
arian
0
i have edited my code a little but still output is 1 can you edit my code and write the right answer please!
7th Jun 2017, 8:03 AM
arian
7th Jun 2017, 8:10 AM
arian
0
bro this code is wrong too! the output is 100 in your code.
7th Jun 2017, 8:56 AM
arian
0
iwant to optain multiplication in output like this: 01 02 03 04 05 06 07 08 09 02 04 06 08 10 12 14 16 18 03 06 09 12 15 18 21 24 27 04 08 12 16 20 24 28 32 36 05 10 15 20 25 30 35 40 45 06 12 18 24 30 36 42 48 54 07 14 21 28 35 42 49 56 63 08 16 24 32 40 48 56 64 72 09 18 27 36 45 54 63 72 81
7th Jun 2017, 9:25 AM
arian
0
i have edited my cod to this but the output is now "segmentation fault" #include<iostream> using namespace std; int main() { int a[10][10]; int j=1, i=1; while (j < 10 || i < 10) { a[i][j] = i * j; while (j <= 10) { j++; } while (j > 10) { i++; j = 1; } } i=1, j=1; while (j <= 10 || i <= 10) { while (j <= 10) { if (a[i][j] < 10) cout << "0" << a[i][j] << "\t"; else if (a[i][j] >= 10) cout << a[i][j] << "\t"; } while (j > 10) { cout << "\n"; j=1; i++; } } return 0; }
7th Jun 2017, 9:35 AM
arian
0
can you upvote me?
7th Jun 2017, 10:47 AM
Milind
Milind - avatar
0
yep
7th Jun 2017, 10:48 AM
arian