當前位置:首頁 » 編程軟體 » 方格編程

方格編程

發布時間: 2024-05-24 18:58:37

編程模擬「地雷游戲」在9x9方格中隨機布上10個地雷按9行9列輸出各格子的數,(有雷為9,無雷為0),在有相

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int map[11][11];
const int N = 9;
void init()
{
memset(map,0,sizeof(map));
int c = 10;
int i,j;
int r;
while(c--)
{
do
{
r = rand()%81;
i = r/9;
j = r%9;
}while(map[i][j]!=0);
map[i][j]=9;
}
}
void print()
{
for(int i=0;i<N;++i)
{
for(int j=0;j<N;++j)
printf("%d",map[i][j]);
printf("\n");
}
}
int main()
{
srand(time(NULL));
init();
print();

return 0;
}
這個每次執行一次 就是隨機一個地雷陣
還有什麼問題再問我 用G++ 編譯

② C語言題(方格取數)

可以用遞歸的方式計算。

熱點內容
linux線程的棧大小 發布:2025-09-18 07:09:42 瀏覽:630
廢舊電腦做linux伺服器 發布:2025-09-18 07:06:50 瀏覽:261
終端配置怎麼寫 發布:2025-09-18 06:44:42 瀏覽:800
ftp手機登陸 發布:2025-09-18 06:43:04 瀏覽:763
emc存儲800電話 發布:2025-09-18 06:32:49 瀏覽:960
c語言編程與設計 發布:2025-09-18 06:09:15 瀏覽:721
2016年預演算法 發布:2025-09-18 06:07:05 瀏覽:622
什麼是廣告腳本設計 發布:2025-09-18 05:52:09 瀏覽:656
移動版我的世界伺服器 發布:2025-09-18 05:38:49 瀏覽:965
使用jsp腳本輸出九九乘法表 發布:2025-09-18 05:22:11 瀏覽:670