Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6. system("chcp 1253");
  7. int row,col,bombs;
  8. int i,x,y;
  9. int **Pedio;
  10. void InputData(int *row, int *col, int* bombs);
  11. void PlaceBombs(int **Pedio,int row,int col,int bombs);
  12.  
  13.  
  14.  
  15. InputData(&row,&col,&bombs);
  16.  
  17. Pedio = (int**)malloc(row*sizeof(int*));
  18. for(i=0; i<row; i++)
  19. *(Pedio+i) = (int*)malloc(col*sizeof(int));
  20.  
  21. PlaceBombs(Pedio,row,col,bombs);
  22.  
  23.  
  24. // printf("Printing the generated grid now...\n");
  25. /* this prints the 2D array onto the console
  26. for(x=0; x<row; x++) {
  27. for(y=0; y<col; y++)
  28. printf("%d ", Pedio[x][y]);
  29. printf("\n");
  30. }
  31. */
  32.  
  33. for(i=0; i<row; i++) //ELEUTHERONOUME TON PINAKA
  34. free(*(Pedio+i));
  35. free(Pedio);
  36. }
  37.  
  38.  
  39. void InputData(int *row, int *col, int* bombs)
  40. {
  41. printf(" Enter the number of rows: ");
  42. scanf("%d", row);
  43. printf("Enter the number of colums: ");
  44. scanf("%d", col);
  45. while(*row<1||*col<1) {
  46. printf("Number of rows or columns cannot be below 1.\nPlease try again...\n");
  47. printf(" Enter the number of rows: ");
  48. scanf("%d",row);
  49. printf("Enter the number of colums: ");
  50. scanf("%d", col);
  51. }
  52. printf("Äþóå áñéèìü âïìâþí: ");
  53. scanf("%d", bombs);
  54. while(*bombs > *row * *col){
  55. printf("Ïé âüìâåò ðñåðåé íá åéíáé ëéãïôåñåò áðï ôï M*N: ");
  56. scanf("%d", bombs);
  57. }
  58. }
  59.  
  60. void PlaceBombs(int **Pedio,int row,int col,int bombs)
  61. {
  62. srand(time(NULL));
  63. int i,j;
  64. int a,b;
  65. for(i=0; i<row; i++){
  66. for(j=0; j<col; j++)
  67. Pedio[i][j] = 0;
  68. printf("%d\n",Pedio[i][j]);
  69. }
  70.  
  71.  
  72. do{
  73. a = rand()% (row-1);
  74. b = rand()% (col-1);
  75. }while(Pedio[a][b]);
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement