#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int arr[9][9], n;
srand(time(0));
for (int i=0; i<9; i++)
{
for (int j=0; j<9; j++)
{
n = rand() % 9;
if (arr[i][j] == n)
{
n = rand() % 9;
arr[i][j] = n;
}
arr[i][j] = n;
}
}
for (int i=0; i<9; i++)
{
for (int j=0; j<9; j++)
{
cout<<" "<<arr[i][j];
}
cout<<endl<<endl;
}
system ("pause");
return (0);
}
I want to generate unique numbers in the 9 by 9 array. The numbers should be in the range from 1 to 9. Each number should not repeat in a particular row or column. I tried to generate random numbers using rand() but I'm not getting unique numbers in the rows & columns. Please help me out to fix this problem soon...