944,047 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 914
  • C RSS
Oct 25th, 2009
0

SUDOKU

Expand Post »
You can insert a no. at any pt. in this program. here is the code:
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<process.h>
  4. #include"goto.c"
  5. void line(void);
  6. void cross(void);
  7. int main()
  8. {
  9. clrscr();
  10. int a[9][9]={8,6,7,5,4,2,3,9,1,
  11. 4,3,2,9,1,8,5,7,6,
  12. 9,5,1,7,6,3,4,2,8,
  13. 5,2,9,6,8,4,7,1,3,
  14. 7,4,8,3,5,1,2,6,9,
  15. 6,1,3,2,7,9,8,5,4,
  16. 1,8,5,4,2,6,9,3,7,
  17. 2,9,6,8,3,7,1,4,5,
  18. 3,7,4,1,9,5,6,8,2},
  19. b[9][9]= {8,6,' ',' ',' ',' ',' ',9,' ',
  20. 4,' ',2,' ',1,' ',5,' ',' ',
  21. ' ',5,' ',7,' ',3,' ',' ',8,
  22. 5,' ',' ',6,8,4,' ',1,' ',
  23. ' ',4,' ',' ',' ',' ',2,6,' ',
  24. ' ',' ',3,2,7,9,8,' ',4,
  25. ' ',' ',' ',' ',' ',6,' ',' ',7,
  26. 2,' ',6,8,3,7,1,' ',' ',
  27. ' ',7,4,' ',' ',' ',' ',8,2},i,j,r=0,c=0,ch,n;
  28.  
  29. textcolor(55);
  30. {cprintf("\n READ THE INSTRUCTIONS CAREFULLY");
  31. printf("\n\n\n");
  32. textcolor(GREEN);
  33. cprintf("1.) FILL NO.S FROM 1 TO 9 IN EVERY ROW , COLUMN & 3*3 BOX");
  34. printf("\n");
  35. cprintf(" 2.) NO Number SHOULD REPEAT MORE THAN ONCE");}
  36. delay(10000);
  37. textcolor(55);
  38. clrscr();
  39. for(i=0;i<9;i++)
  40. {
  41. printf("\n");
  42. for(j=0;j<9;j++)
  43. {printf("%3d",b[i][j]);
  44. if (b[i][j]==32)
  45. printf("\b\b _");}
  46. printf("\n");
  47. }
  48. gotorc(0,0);
  49. printf("%c",218);
  50. for(i=0;i<17;i++)
  51. printf("\n%c",179);
  52. printf("\n%c",192);
  53. line();
  54.  
  55. gotorc(0,1);line();
  56. gotorc(6,1);line();
  57. gotorc(12,1);line();
  58. gotorc(0,9);cross();
  59. gotorc(0,18);cross();
  60. gotorc(0,27);cross();
  61. gotorc(6,31);
  62. printf("1.use errow key to move");
  63. gotorc(7,31);
  64. printf("2.press insert to insert a no. & then press enter");
  65. gotorc(8,31);
  66. printf("3.insert a no. at blank given");
  67. gotorc(0,0);
  68. while(1)
  69. {
  70. ch=getkey();
  71. switch(ch)
  72. {
  73. case 77:
  74. gotorc(r,++c);
  75. break;
  76. case 80:
  77. {
  78. gotorc(++r,c); break;
  79. }
  80. case 75:
  81. {
  82. gotorc(r,--c); break;
  83. }
  84. case 1:
  85. exit(0);
  86. case 72:
  87. gotorc(--r,c);break;
  88. case 82:
  89. scanf("%d",&n);
  90. gotorc(r,c);
  91. printf("%d",n);
  92. }
  93. }
  94. getch();
  95. return(0);
  96. }
  97.  
  98.  
  99. void line(void)
  100. {
  101. int i;
  102. for(i=0;i<27;i++)
  103. cprintf("%c",196);
  104. }
  105.  
  106.  
  107. void cross(void)
  108. {
  109. int i;
  110. for(i=0;i<=18;i++)
  111. {
  112. if(i==0)
  113. cprintf("%c\n",194);
  114. else if(i==6||i==12)
  115. cprintf("\b%c\n",197);
  116. else if(i==18)
  117. cprintf("\b%c\n",193);
  118. else
  119. cprintf("\b%c\n",179);
  120. }
  121. }

run this code in your TC.
you need to copy the foll. in TC
GOTO.C
please see attachment goto.c


please let me know how can i check that my filled sudoku is right or wrong. (note that it is not necessary to fill first blank first , i can fill it randomly)
Last edited by WaltP; Oct 27th, 2009 at 3:19 am. Reason: Added CODE tags -- with all the help about them, how could you miss using them????
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kirit275 is offline Offline
13 posts
since Oct 2009
Oct 26th, 2009
1
Re: SUDOKU
if you would like to get a meaningful response, please consider the following:

How to Ask a Question

Please Use Code Tags
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: how can i treate with execvp?!!
Next Thread in C Forum Timeline: c language software





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC