Friday, July 31, 2009

HELP!!!Write pseudocode that creates a two-dimensional array of size 5 x 5 (C++ PROGRAMING)?

Write pseudocode that creates a two-dimensional array of size 5 x 5, then uses nested for loops to initialize it with 'X' and '.' characters so that it looks like this:





X...X


.X.X.


..X..


.X.X.


X...X








Your code should contain only two assignment statements involving the array: one of the form





* myarray[x][y] %26lt;- 'X'





and of of the form





* myarray[x][y] %26lt;- '.'

HELP!!!Write pseudocode that creates a two-dimensional array of size 5 x 5 (C++ PROGRAMING)?
Here's the program:





#include %26lt;iostream%26gt;


using namespace std;





int _tmain(int argc, _TCHAR* argv[])


{


const int PICTURE_SIDE = 5;


char picture[PICTURE_SIDE][PICTURE_SIDE];





int x1 = 0;


int x2 = 4;





for (int i = 0; i %26lt; PICTURE_SIDE; i++)


{





for (int j = 0; j %26lt; PICTURE_SIDE; j++)


{


if (j == x1 || j == x2)


picture[i][j] = 'X';


else


picture[i][j] = '.';





cout %26lt;%26lt;picture[i][j] %26lt;%26lt; " ";


}


x1++;


x2--;





cout %26lt;%26lt; endl;


}


return 0;


}





Email me if you want me to explain how I figured it out.

floral

No comments:

Post a Comment