Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- system("chcp 1253");
- int row,col,bombs;
- int i,x,y;
- int **Pedio;
- void InputData(int *row, int *col, int* bombs);
- void PlaceBombs(int **Pedio,int row,int col,int bombs);
- InputData(&row,&col,&bombs);
- Pedio = (int**)malloc(row*sizeof(int*));
- for(i=0; i<row; i++)
- *(Pedio+i) = (int*)malloc(col*sizeof(int));
- PlaceBombs(Pedio,row,col,bombs);
- // printf("Printing the generated grid now...\n");
- /* this prints the 2D array onto the console
- for(x=0; x<row; x++) {
- for(y=0; y<col; y++)
- printf("%d ", Pedio[x][y]);
- printf("\n");
- }
- */
- for(i=0; i<row; i++) //ELEUTHERONOUME TON PINAKA
- free(*(Pedio+i));
- free(Pedio);
- }
- void InputData(int *row, int *col, int* bombs)
- {
- printf(" Enter the number of rows: ");
- scanf("%d", row);
- printf("Enter the number of colums: ");
- scanf("%d", col);
- while(*row<1||*col<1) {
- printf("Number of rows or columns cannot be below 1.\nPlease try again...\n");
- printf(" Enter the number of rows: ");
- scanf("%d",row);
- printf("Enter the number of colums: ");
- scanf("%d", col);
- }
- printf("Äþóå áñéèìü âïìâþí: ");
- scanf("%d", bombs);
- while(*bombs > *row * *col){
- printf("Ïé âüìâåò ðñåðåé íá åéíáé ëéãïôåñåò áðï ôï M*N: ");
- scanf("%d", bombs);
- }
- }
- void PlaceBombs(int **Pedio,int row,int col,int bombs)
- {
- srand(time(NULL));
- int i,j;
- int a,b;
- for(i=0; i<row; i++){
- for(j=0; j<col; j++)
- Pedio[i][j] = 0;
- printf("%d\n",Pedio[i][j]);
- }
- do{
- a = rand()% (row-1);
- b = rand()% (col-1);
- }while(Pedio[a][b]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement