I wrote the code for 3x3 array to get random numbers as a its elements but, I am
getting all row elements same. can anybody tell me what is wrong with this.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int matrix[3][3];
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
matrix[x][y] = rand()%8;
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
cout << matrix[x][y] << ' ';
cout << endl;
}
system("pause"); //Ignore this if you're using Code::blocks
}
Try running that and tell me if it's what you were going for.