各位帮我看看为什么不能输出@而是?代码比较多各位帮我看看

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define N 30
#define M 30
int main() {
printf("请输入地雷数量:");
int n;
scanf_s("%d", &n);
char a[N][M];
int z, y;
srand(unsigned int(time(NULL)));
z = rand() % 30;
y = rand() % 30;
int i;
for (i = 0; i < n; i++) {
a[z][y] = '@';
}
int j;
char x = '0';
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
if (a[i][j] != '@'){
if (1 <= i && i <= 28) {
if (1 <= j && j <= 28) {
if (a[i][j + 1] == '@') //1
{
x += 1;
}
if (a[i + 1][j + 1] == '@') //2
{
x += 1;
}
if (a[i + 1][j] == '@') //3
{
x += 1;
}
if (a[i + 1][j - 1] == '@') //4
{
x += 1;
}
if (a[i][j - 1] == '@') //5
{
x += 1;
}
if (a[i - 1][j - 1] == '@') //6
{
x += 1;
}
if (a[i - 1][j] == '@') //7
{
x += 1;
}
if (a[i - 1][j + 1] == '@') //8
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 0) {
if (j == 0)
{
if (a[i][j + 1] == '@')
{
x += 1;
}
if (a[i + 1][j + 1] == '@')
{
x += 1;
}
if (a[i + 1][j] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 0) {
if (j == 29)
{
if (a[i][j - 1] == '@')
{
x += 1;
}
if (a[i + 1][j + 1] == '@')
{
x += 1;
}
if (a[i + 1][j - 1] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 29) {
if (j == 0)
{
if (a[i - 1][j] == '@')
{
x += 1;
}
if (a[i - 1][j + 1] == '@')
{
x += 1;
}
if (a[i][j + 1] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 29) {
if (j == 29)
{
if (a[i - 1][j] == '@')
{
x += 1;
}
if (a[i][j - 1] == '@')
{
x += 1;
}
if (a[i - 1][j - 1] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 0) {
for (j = 1; j < 29; j++) {
if (a[i][j - 1] == '@')
{
x += 1;
}
if (a[i + 1][j - 1] == '@')
{
x += 1;
}
if (a[i + 1][j] == '@')
{
x += 1;
}
if (a[i + 1][j + 1] == '@')
{
x += 1;
}
if (a[i][j + 1] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (j == 0) {
for (i = 1; i < 29; i++) {
if (a[i - 1][j] == '@')
{
x += 1;
}
if (a[i - 1][j + 1] == '@')
{
x += 1;
}
if (a[i][j + 1] == '@')
{
x += 1;
}
if (a[i + 1][j + 1] == '@')
{
x += 1;
}
if (a[i + 1][j] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (i == 29) {
for (j = 1; j < 29; j++) {
if (a[i - 1][j] == '@')
{
x += 1;
}
if (a[i - 1][j - 1] == '@')
{
x += 1;
}
if (a[i][j - 1] == '@')
{
x += 1;
}
if (a[i][j + 1] == '@')
{
x += 1;
}
if (a[i - 1][j + 1] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
if (j == 29) {
for (i = 1; i < 29; i++) {
if (a[i - 1][j] == '@')
{
x += 1;
}
if (a[i - 1][j - 1] == '@')
{
x += 1;
}
if (a[i][j - 1] == '@')
{
x += 1;
}
if (a[i + 1][j - 1] == '@')
{
x += 1;
}
if (a[i + 1][j] == '@')
{
x += 1;
}
a[i][j] = x;
x = '0';
}
}
}
}
}
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
printf("%c\t", a[i][j]);
if (j == 29)
printf("\n");
}
}

运行结果及报错内容

运行结果是问号不是@,而且好像也不能像题目一样输出

我的解答思路和尝试过的方法
我想要达到的结果

z = rand() % 30;
y = rand() % 30;
int i;
for (i = 0; i < n; i++) {
a[z][y] = '@';
}
改为

int i;
for (i = 0; i < n; i++) {
z = rand() % 30;
y = rand() % 30;
a[z][y] = '@';
}