0

Convert one dimensional array (array[8]) to two dimensional array (array[2][4]) .

please help

20th Sep 2021, 5:08 PM
Younis Ahmad
Younis Ahmad - avatar
11 odpowiedzi
+ 3
Martin Taylor thank you
20th Sep 2021, 8:26 PM
Younis Ahmad
Younis Ahmad - avatar
+ 2
int main() { int k[8]={15,3,21,8,3,12,5,3}; cout<<k[8]; int a[2][4]={{15,3,21,8},{3,12,5,3}} for(int i=0;i<2;i++) { for(int j=0;j<4;j++) { cout<<a[i][j]<<" "; } } return 0; }
20th Sep 2021, 5:16 PM
Younis Ahmad
Younis Ahmad - avatar
+ 2
mesarthim thank you
20th Sep 2021, 6:33 PM
Younis Ahmad
Younis Ahmad - avatar
0
Younis Ahmad Did you solve your problem in the comment or just add your code lines? It looks still error. Could you specify?
20th Sep 2021, 5:32 PM
mesarthim
mesarthim - avatar
0
i don´t know
20th Sep 2021, 5:43 PM
Younis Ahmad
Younis Ahmad - avatar
0
I checked and a ";" remaining. I added. Also if you print the elements of k, you should use a loop to write all elements. #include <iostream> using namespace std; int main(){ int k[8]={15,3,21,8,3,12,5,3}; for(int s = 0; s < 8; s++){ cout<<k[s] << " "; } int a[2][4]={{15,3,21,8},{3,12,5,3}}; for(int i=0;i<2;i++){ for(int j=0;j<4;j++){ cout<<a[i][j]<<" "; } } return 0; } Also, I suppose the main problem is how to convert it, am I right?
20th Sep 2021, 5:46 PM
mesarthim
mesarthim - avatar
0
yes exactly
20th Sep 2021, 5:51 PM
Younis Ahmad
Younis Ahmad - avatar
0
You should check. I hope, it helps. Happy coding! https://code.sololearn.com/cNGPkZa7MYTq/?ref=app
20th Sep 2021, 6:08 PM
mesarthim
mesarthim - avatar
0
how i can do it
20th Sep 2021, 6:31 PM
Younis Ahmad
Younis Ahmad - avatar