It's a complicated program but I guess I've done something wrong here from the git go I need to generate 3 random 3x3 matricies I write this code and it pops up way too many matricies and then brings up an error and closes my program what's going on and how can I fix it?
my program
#include %26lt;iostream.h%26gt;
#include %26lt;stdlib.h%26gt;
void main(void)
{
int x[3][3];
int y[3][3];
int z[3][3];
int i,j;
for (i=1; i%26lt;4; i++){
for (j=1; j%26lt;4; j++){
x[i][j]=rand () %201;
}
}
for (i=1; i%26lt;4; i++){
for (j=1; j%26lt;4; j++){
y[i][j]=rand ()%201;
}
}
for (i=1; i%26lt;4; i++){
for (j=1; j%26lt;4; j++){
z[i][j]=rand ()%201;
}
}
for(i=1;i%26lt;4;i++){
cout%26lt;%26lt;x[i][1]%26lt;%26lt;" "%26lt;%26lt;x[i][2]%26lt;%26lt;" "%26lt;%26lt;x[i][3];
cout%26lt;%26lt;endl;
}
for(i=1;i%26lt;4;i++){
cout%26lt;%26lt;y[i][1]%26lt;%26lt;" "%26lt;%26lt;y[i][2]%26lt;%26lt;" "%26lt;%26lt;y[i][3];
cout%26lt;%26lt;endl;
}
for(i=1;i%26lt;4;i++){
cout%26lt;%26lt;z[i][1]%26lt;%26lt;" "%26lt;%26lt;z[i][2]%26lt;%26lt;" "%26lt;%26lt;z[i][3];
cout%26lt;%26lt;endl;
}
}
I have to write this C++ program for my programming class?
#include %26lt;iostream.h%26gt;
#include %26lt;stdlib.h%26gt;
void main(void)
{
int x[3][3];
int y[3][3];
int z[3][3];
int i,j;
for (i=0; i%26lt;3; i++){
for (j=0; j%26lt;3; j++){
x[i][j]=rand () %201;
y[i][j]=rand ()%201;
z[i][j]=rand ()%201;
} /* end for j */
} /* end for i */
for(i=0;i%26lt;3;i++){
cout%26lt;%26lt;x[i][1]%26lt;%26lt;" "%26lt;%26lt;x[i][2]%26lt;%26lt;" "%26lt;%26lt;x[i][3];
cout%26lt;%26lt;endl;
} /* end for i */
for(i=0;i%26lt;3;i++){
cout%26lt;%26lt;y[i][1]%26lt;%26lt;" "%26lt;%26lt;y[i][2]%26lt;%26lt;" "%26lt;%26lt;y[i][3];
cout%26lt;%26lt;endl;
} /* end for i */
for(i=0;i%26lt;3;i++){
cout%26lt;%26lt;z[i][1]%26lt;%26lt;" "%26lt;%26lt;z[i][2]%26lt;%26lt;" "%26lt;%26lt;z[i][3];
cout%26lt;%26lt;endl;
} /* end for i */
} /* end main */
Reply:You need such as:
for (i=0; i%26lt;3; i++)
Reply:The numbering starts at 0.
So a [3][3] has elements:
[0][0],[0][1],[0][2]
[1][0],[1][1],[1][2]
[2][0],[2][1],[2][2]
You started assigning values at 1, 2, 3.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment