C++ Sudoku
Minggu, 13 Juli 2014
Add Comment
#include <iostream>
#include <conio.h>
main ()
{ int a[3][3],b[3][3],c[3][3],d[3][3],e[3][3],f[3][3],g[3][3],h[3][3],i[3][3];
a[0][0]=6;
a[0][1]=3;
a[0][2]=7;
a[1][0]=5;
a[1][1]=1;
a[1][2]=4;
a[2][0]=8;
a[2][1]=9;
a[2][2]=2;
b[0][0]=2;
b[0][1]=5;
b[0][2]=4;
b[1][0]=8;
b[1][1]=9;
b[1][2]=6;
b[2][0]=1;
b[2][1]=7;
b[2][2]=3;
c[0][0]=8;
c[0][1]=9;
c[0][2]=1;
c[1][0]=1;
c[1][1]=5;
c[1][2]=7;
c[2][0]=6;
c[2][1]=2;
c[2][2]=9;
d[0][0]=3;
d[0][1]=4;
d[0][2]=8;
d[1][0]=1;
d[1][1]=5;
d[1][2]=8;
d[2][0]=6;
d[2][1]=2;
d[2][2]=9;
e[0][0]=9;
e[0][1]=7;
e[0][2]=6;
e[1][0]=2;
e[1][1]=4;
e[1][2]=8;
e[2][0]=3;
e[2][1]=5;
e[2][2]=1;
f[0][0]=5;
f[0][1]=1;
f[0][2]=2;
f[1][0]=3;
f[1][1]=6;
f[1][2]=9;
f[2][0]=7;
f[2][1]=4;
f[2][2]=8;
g[0][0]=1;
g[0][1]=6;
g[0][2]=5;
g[1][0]=9;
g[1][1]=3;
g[1][2]=2;
g[2][0]=4;
g[2][1]=8;
g[2][2]=7;
h[0][0]=7;
h[0][1]=2;
h[0][2]=3;
h[1][0]=4;
h[1][1]=8;
h[1][2]=5;
h[2][0]=9;
h[2][1]=1;
h[2][2]=6;
i[0][0]=4;
i[0][1]=8;
i[0][2]=9;
i[1][0]=6;
i[1][1]=7;
i[1][2]=1;
i[2][0]=2;
i[2][1]=3;
i[2][2]=5;
cout<<"*************************"<<endl;
cout<<"* "<<a[0][0]<<" "<<a[0][1]<<" "<<a[0][2];
cout<<" * "<<a[1][0]<<" "<<a[1][1]<<" "<<a[1][2];
cout<<" * "<<a[2][0]<<" "<<a[2][1]<<" "<<a[2][2]<<" *"<<endl;
cout<<"* "<<b[0][0]<<" "<<b[0][1]<<" "<<b[0][2];
cout<<" * "<<b[1][0]<<" "<<b[1][1]<<" "<<b[1][2];
cout<<" * "<<b[2][0]<<" "<<b[2][1]<<" "<<b[2][2]<<" *"<<endl;
cout<<"* "<<c[0][0]<<" "<<c[0][1]<<" "<<c[0][2];
cout<<" * "<<c[1][0]<<" "<<c[1][1]<<" "<<c[1][2];
cout<<" * "<<c[2][0]<<" "<<c[2][1]<<" "<<c[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
cout<<"* "<<d[0][0]<<" "<<d[0][1]<<" "<<d[0][2];
cout<<" * "<<d[1][0]<<" "<<d[1][1]<<" "<<d[1][2];
cout<<" * "<<d[2][0]<<" "<<d[2][1]<<" "<<d[2][2]<<" *"<<endl;
cout<<"* "<<e[0][0]<<" "<<e[0][1]<<" "<<e[0][2];
cout<<" * "<<e[1][0]<<" "<<e[1][1]<<" "<<e[1][2];
cout<<" * "<<e[2][0]<<" "<<e[2][1]<<" "<<e[2][2]<<" *"<<endl;
cout<<"* "<<f[0][0]<<" "<<f[0][1]<<" "<<f[0][2];
cout<<" * "<<f[1][0]<<" "<<f[1][1]<<" "<<f[1][2];
cout<<" * "<<f[2][0]<<" "<<f[2][1]<<" "<<f[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
cout<<"* "<<g[0][0]<<" "<<g[0][1]<<" "<<g[0][2];
cout<<" * "<<g[1][0]<<" "<<g[1][1]<<" "<<g[1][2];
cout<<" * "<<g[2][0]<<" "<<g[2][1]<<" "<<g[2][2]<<" *"<<endl;
cout<<"* "<<h[0][0]<<" "<<h[0][1]<<" "<<h[0][2];
cout<<" * "<<h[1][0]<<" "<<h[1][1]<<" "<<h[1][2];
cout<<" * "<<h[2][0]<<" "<<h[2][1]<<" "<<h[2][2]<<" *"<<endl;
cout<<"* "<<i[0][0]<<" "<<i[0][1]<<" "<<i[0][2];
cout<<" * "<<i[1][0]<<" "<<i[1][1]<<" "<<i[1][2];
cout<<" * "<<i[2][0]<<" "<<i[2][1]<<" "<<i[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
getch();
}
#include <conio.h>
main ()
{ int a[3][3],b[3][3],c[3][3],d[3][3],e[3][3],f[3][3],g[3][3],h[3][3],i[3][3];
a[0][0]=6;
a[0][1]=3;
a[0][2]=7;
a[1][0]=5;
a[1][1]=1;
a[1][2]=4;
a[2][0]=8;
a[2][1]=9;
a[2][2]=2;
b[0][0]=2;
b[0][1]=5;
b[0][2]=4;
b[1][0]=8;
b[1][1]=9;
b[1][2]=6;
b[2][0]=1;
b[2][1]=7;
b[2][2]=3;
c[0][0]=8;
c[0][1]=9;
c[0][2]=1;
c[1][0]=1;
c[1][1]=5;
c[1][2]=7;
c[2][0]=6;
c[2][1]=2;
c[2][2]=9;
d[0][0]=3;
d[0][1]=4;
d[0][2]=8;
d[1][0]=1;
d[1][1]=5;
d[1][2]=8;
d[2][0]=6;
d[2][1]=2;
d[2][2]=9;
e[0][0]=9;
e[0][1]=7;
e[0][2]=6;
e[1][0]=2;
e[1][1]=4;
e[1][2]=8;
e[2][0]=3;
e[2][1]=5;
e[2][2]=1;
f[0][0]=5;
f[0][1]=1;
f[0][2]=2;
f[1][0]=3;
f[1][1]=6;
f[1][2]=9;
f[2][0]=7;
f[2][1]=4;
f[2][2]=8;
g[0][0]=1;
g[0][1]=6;
g[0][2]=5;
g[1][0]=9;
g[1][1]=3;
g[1][2]=2;
g[2][0]=4;
g[2][1]=8;
g[2][2]=7;
h[0][0]=7;
h[0][1]=2;
h[0][2]=3;
h[1][0]=4;
h[1][1]=8;
h[1][2]=5;
h[2][0]=9;
h[2][1]=1;
h[2][2]=6;
i[0][0]=4;
i[0][1]=8;
i[0][2]=9;
i[1][0]=6;
i[1][1]=7;
i[1][2]=1;
i[2][0]=2;
i[2][1]=3;
i[2][2]=5;
cout<<"*************************"<<endl;
cout<<"* "<<a[0][0]<<" "<<a[0][1]<<" "<<a[0][2];
cout<<" * "<<a[1][0]<<" "<<a[1][1]<<" "<<a[1][2];
cout<<" * "<<a[2][0]<<" "<<a[2][1]<<" "<<a[2][2]<<" *"<<endl;
cout<<"* "<<b[0][0]<<" "<<b[0][1]<<" "<<b[0][2];
cout<<" * "<<b[1][0]<<" "<<b[1][1]<<" "<<b[1][2];
cout<<" * "<<b[2][0]<<" "<<b[2][1]<<" "<<b[2][2]<<" *"<<endl;
cout<<"* "<<c[0][0]<<" "<<c[0][1]<<" "<<c[0][2];
cout<<" * "<<c[1][0]<<" "<<c[1][1]<<" "<<c[1][2];
cout<<" * "<<c[2][0]<<" "<<c[2][1]<<" "<<c[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
cout<<"* "<<d[0][0]<<" "<<d[0][1]<<" "<<d[0][2];
cout<<" * "<<d[1][0]<<" "<<d[1][1]<<" "<<d[1][2];
cout<<" * "<<d[2][0]<<" "<<d[2][1]<<" "<<d[2][2]<<" *"<<endl;
cout<<"* "<<e[0][0]<<" "<<e[0][1]<<" "<<e[0][2];
cout<<" * "<<e[1][0]<<" "<<e[1][1]<<" "<<e[1][2];
cout<<" * "<<e[2][0]<<" "<<e[2][1]<<" "<<e[2][2]<<" *"<<endl;
cout<<"* "<<f[0][0]<<" "<<f[0][1]<<" "<<f[0][2];
cout<<" * "<<f[1][0]<<" "<<f[1][1]<<" "<<f[1][2];
cout<<" * "<<f[2][0]<<" "<<f[2][1]<<" "<<f[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
cout<<"* "<<g[0][0]<<" "<<g[0][1]<<" "<<g[0][2];
cout<<" * "<<g[1][0]<<" "<<g[1][1]<<" "<<g[1][2];
cout<<" * "<<g[2][0]<<" "<<g[2][1]<<" "<<g[2][2]<<" *"<<endl;
cout<<"* "<<h[0][0]<<" "<<h[0][1]<<" "<<h[0][2];
cout<<" * "<<h[1][0]<<" "<<h[1][1]<<" "<<h[1][2];
cout<<" * "<<h[2][0]<<" "<<h[2][1]<<" "<<h[2][2]<<" *"<<endl;
cout<<"* "<<i[0][0]<<" "<<i[0][1]<<" "<<i[0][2];
cout<<" * "<<i[1][0]<<" "<<i[1][1]<<" "<<i[1][2];
cout<<" * "<<i[2][0]<<" "<<i[2][1]<<" "<<i[2][2]<<" *"<<endl;
cout<<"*************************"<<endl;
getch();
}
0 Response to "C++ Sudoku"
Posting Komentar