Advertisement
MotorisedEditor

Untitled

Nov 17th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. main(){
  5. int size_a, i,j, ai,aj, bi,bj, counter, ap_i, ap_j, times;
  6.  
  7. printf("Enter board size: ");
  8. size_a=4;printf("4\n");//scanf("%d",&size_a);
  9.  
  10. int a[size_a][size_a];
  11.  
  12. counter=1;
  13. for(j=0;j<size_a;j++){
  14. for(i=0;i<size_a;i++){
  15. a[i][j]=counter;
  16. counter++;
  17. }
  18. }
  19.  
  20. printf("\n");
  21. for(j=0;j<size_a;j++){
  22. for(i=0;i<size_a;i++){
  23. if(a[i][j]<10){
  24. printf(" %d",a[i][j]);
  25. }else if(a[i][j]>=10 && a[i][j]<100){
  26. printf(" %d",a[i][j]);
  27. }else{
  28. printf(" %d",a[i][j]);
  29. }
  30. }
  31. printf("\n");
  32. }
  33. printf("\n");
  34.  
  35.  
  36. printf("Enter IDs of number A: ");
  37. ai=0;aj=0;printf("0 0\n");//scanf("%d %d",&ai,&aj);
  38. printf("Enter IDs of number B: ");
  39. bi=2;bj=3;printf("2 3\n");//scanf("%d %d",&bi,&bj);
  40.  
  41. ap_i = bi - ai;
  42. if(ap_i<0){ap_i=ap_i*-1;}
  43. ap_j = bj - aj;
  44. if(ap_j<0){ap_j=ap_j*-1;}
  45. times = 1+(ap_i*ap_j);
  46.  
  47. printf("\nThere are '%d' possible paths!!\n\n",times);
  48.  
  49.  
  50.  
  51. int k, done, done_i, done_j;
  52.  
  53.  
  54.  
  55.  
  56. int reachi=bi, reachj=bj, printed;
  57. for(k=1;k<=times;k++){
  58. printf("%d) \n",k);
  59.  
  60.  
  61. i=ai;
  62. j=aj;
  63.  
  64. done=0;
  65. while(done==0){
  66.  
  67. if(i<=reachi){
  68. getch();
  69. printed=a[i][j];
  70. printf("%d ",printed);
  71. i++;
  72. if(i>reachi){
  73. done_i=1;
  74. i--;
  75. }
  76. }
  77.  
  78.  
  79. if(done_i==1){
  80. j++;
  81.  
  82. }
  83.  
  84.  
  85.  
  86.  
  87. if(printed==a[bi][bj]){
  88. done=1;
  89. reachi--;
  90. }
  91. }
  92.  
  93.  
  94. printf("\n");
  95. }
  96.  
  97. getch();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement