I couldn't run this program as i had not expected.this is basically an unfinished sudoku generating program.the codes showed below is for generating the #s but i hadn't taken 3X3 squares into consideration.Can someone help me ,thanks!!
#include<iostream>
#include<time.h>
usingnamespace std;
int main()
{
srand(time(0));
int a[9][9];
for (int i=1;i<=9;i++)
for (int j=1;j<=9;j++)
a[i][j]=0;
int flagx,flagy,store=0; //flagx :to check if the number in a row has existed before
//flagy :numbers in column
for (int i=1;i<=9;i++){ //i:row
for (int j=1;j<=9;j++) //j:column
{
do
{
flagx=0,flagy=0;
store=rand()%9+1;
for (int x=1;x<j;x++) //this loop is used to check if the number is valid in a row
{
if (a[i][x]!=store)
flagx++;
}
for (int y=1;y<i;y++) //this is for column (the loops for row and column both work out seperately but i couldn't combine them )
{
if (a[y][j]!=store)
flagy++;
} //i need another loop for 3X3 square,could use modulous to do that,but i need to work both row and column out first
}
while(flagx!=j-1||flagy!=i-1);
a[i][j]=store;
}
cout<<"outside"<<i<<endl;
}
for (int i=1;i<=9;i++)
{
cout<<"sdkjkl"; //just to see if this loop work.and it turns out the program was stuck in the while loop()
for (int j=1;j<=9;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
system("pause");
return 0;
}