diff --git a/minesweeper.c b/minesweeper.c new file mode 100644 index 0000000..ba91c38 --- /dev/null +++ b/minesweeper.c @@ -0,0 +1,47 @@ +/* Write a program minesweeper.c that takes in dimensions m and n from the user and a probability p, then generates a Minesweeper board of size m x n where each cell has a probability of p to be a mine (probability is a number between 0 and 1). Each cell that is not a mine contains a number representing how many mines (above, below, left, right, and diagonal) neighbor that "safe" cell. Print the board, representing each mine as an asterisk (*). + Your program should check for valid input. + Some tips: * You may want to store your board as an integer array, with some constant value for the mines (e.g. 99), then convert the integer representation to a * for printing*/ +#include +#include +#include +int main(){ + + int m; + int n; + printf("enter m(rows)\n"); + scanf("%d", &m); + printf("enter n(colums)\n"); + scanf("%d", &n); + char board[m] [n]; + int row=0; + int col=0; + srand(time(NULL)); + int x; + float p; + printf("Enter a probablity\n"); + scanf("%f", &p); + for (row=0;row