Answer to Question #20525 in C++ for adrian thomas

Question #20525
Write a C++ function to store the elements of two dimensionl array into one dimensional array row wise
1
Expert's answer
2012-12-27T09:07:32-0500

#include<iostream>
#include<fstream>

using namespace std;

int input(istream& in=cin)
{
int x;
in >> x;
return x;
}

int main()
{
int board[9][9]; //creates a 9*9 matrix or a 2d array.

for(int i=0; i<9; i++) //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
board[i][j] = input(); //you can also connect to the file
//and place the name of your ifstream in the input after opening the file will
//let you read from the file.
}
}

for(int i=0; i<9; i++) //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
cout << board[i][j] << " ";
}
cout << endl;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS