技術問答
技術文章
iT 徵才
聊天室
2025 鐵人賽
登入/註冊
問答
文章
Tag
邦友
鐵人賽
搜尋
0
這C語言的程式碼那些地方出錯?
c語言
c語言 遞迴
自學c語言
vuj8104
2020-10-03 23:23:42
‧
1752 瀏覽
分享至
回答
討論
6
邀請回答
追蹤
檢舉
×
邀請回答
輸入邀請回答者的帳號或暱稱
Loading
找不到結果。
已達邀請上限
邀請回答
{{ result.user.nickname }}
{{ result.user.account }}
已邀請的邦友
{{ invite_list.length }}
/5
取消邀請
{{ invite.nickname }}
{{ invite.account }}
看更多先前的討論...
收起先前的討論...
微甜的酸
iT邦新手 2 級 ‧
2020-10-04 09:05:07
檢舉
程式碼的部分請改成下方這樣子:
```c
程式碼
```
程式碼的部分請改成下方這樣子: ```c 程式碼 ```
修改
vuj8104
iT邦新手 4 級 ‧
2020-10-04 11:19:51
檢舉
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int size;
int recursion(int [][size],int,int,int,int);
int main()
{
int i,j,row,col,count;
printf("Enter the size of the square:");
scanf("%d",&size);
if(size == 5 || size == 7 || size == 9)
{
int arr[size][size];
for(i = 0 ; i < size ; i ++)
{
for(j = 0 ; j < size ; j++)
{
arr[i][j] = 0;
}
}
srand(time(NULL));
i = rand() % size;
j = rand() % size;
arr[i][j] = 1;
recursion(arr[size][size],size*size,i,j,2);
for(i = 0 ; i < size ; i ++)
{
for(j = 0 ; j < size ; j++)
{
printf("%2d ",arr[i][j]);
}
printf("\n");
}
}
return 0;
}
int recursion(int arr[][size],int num,int i,int j,int count)
{
int row,col;
if(count <= num)
{
row = (i - 1 < 0) ? (size - 1) : (i - 1);
col = (j - 1 < 0) ? (size - 1) : (j - 1);
if(arr[row][col] != 0)
{
i = (++i) % size;
}
else
{
i = row;
j = col;
}
arr[i][j] = count;
return recursion(arr[size][size],num-1,i,j,count++);
}
}
#include<stdio.h> #include<stdlib.h> #include<time.h> int size; int recursion(int [][size],int,int,int,int); int main() { int i,j,row,col,count; printf("Enter the size of the square:"); scanf("%d",&size); if(size == 5 || size == 7 || size == 9) { int arr[size][size]; for(i = 0 ; i < size ; i ++) { for(j = 0 ; j < size ; j++) { arr[i][j] = 0; } } srand(time(NULL)); i = rand() % size; j = rand() % size; arr[i][j] = 1; recursion(arr[size][size],size*size,i,j,2); for(i = 0 ; i < size ; i ++) { for(j = 0 ; j < size ; j++) { printf("%2d ",arr[i][j]); } printf("\n"); } } return 0; } int recursion(int arr[][size],int num,int i,int j,int count) { int row,col; if(count <= num) { row = (i - 1 < 0) ? (size - 1) : (i - 1); col = (j - 1 < 0) ? (size - 1) : (j - 1); if(arr[row][col] != 0) { i = (++i) % size; } else { i = row; j = col; } arr[i][j] = count; return recursion(arr[size][size],num-1,i,j,count++); } }
修改
vuj8104
iT邦新手 4 級 ‧
2020-10-04 11:36:07
檢舉
```
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int size;
int recursion(int [][size],int,int,int,int);
int main()
{
int i,j,row,col,count;
printf("Enter the size of the square:");
scanf("%d",&size);
if(size == 5 || size == 7 || size == 9)
{
int arr[size][size];
for(i = 0 ; i < size ; i ++)
{
for(j = 0 ; j < size ; j++)
{
arr[i][j] = 0;
}
}
srand(time(NULL));
i = rand() % size;
j = rand() % size;
arr[i][j] = 1;
recursion(arr[size][size],size*size,i,j,2);
for(i = 0 ; i < size ; i ++)
{
for(j = 0 ; j < size ; j++)
{
printf("%2d ",arr[i][j]);
}
printf("\n");
}
}
return 0;
}
int recursion(int arr[][size],int num,int i,int j,int count)
{
int row,col;
if(count <= num)
{
row = (i - 1 < 0) ? (size - 1) : (i - 1);
col = (j - 1 < 0) ? (size - 1) : (j - 1);
if(arr[row][col] != 0)
{
i = (++i) % size;
}
else
{
i = row;
j = col;
}
arr[i][j] = count;
return recursion(arr[size][size],num-1,i,j,count++);
}
}
```
``` #include<stdio.h> #include<stdlib.h> #include<time.h> int size; int recursion(int [][size],int,int,int,int); int main() { int i,j,row,col,count; printf("Enter the size of the square:"); scanf("%d",&size); if(size == 5 || size == 7 || size == 9) { int arr[size][size]; for(i = 0 ; i < size ; i ++) { for(j = 0 ; j < size ; j++) { arr[i][j] = 0; } } srand(time(NULL)); i = rand() % size; j = rand() % size; arr[i][j] = 1; recursion(arr[size][size],size*size,i,j,2); for(i = 0 ; i < size ; i ++) { for(j = 0 ; j < size ; j++) { printf("%2d ",arr[i][j]); } printf("\n"); } } return 0; } int recursion(int arr[][size],int num,int i,int j,int count) { int row,col; if(count <= num) { row = (i - 1 < 0) ? (size - 1) : (i - 1); col = (j - 1 < 0) ? (size - 1) : (j - 1); if(arr[row][col] != 0) { i = (++i) % size; } else { i = row; j = col; } arr[i][j] = count; return recursion(arr[size][size],num-1,i,j,count++); } } ```
修改
vuj8104
iT邦新手 4 級 ‧
2020-10-04 11:39:48
檢舉
怎麼用啊?我不會抱歉
怎麼用啊?我不會抱歉
修改
Daniel_Yen
iT邦新手 5 級 ‧
2020-10-04 13:30:43
檢舉
修改文章,程式碼前後加上去
修改文章,程式碼前後加上去
修改
vuj8104
iT邦新手 4 級 ‧
2020-10-04 14:16:07
檢舉
重新發問了
https://ithelp.ithome.com.tw/m/questions/10200536
重新發問了 https://ithelp.ithome.com.tw/m/questions/10200536
修改
登入發表討論
熱門推薦
{{ item.subject }}
{{ item.channelVendor }}
|
{{ item.webinarstarted }}
|
{{ formatDate(item.duration) }}
直播中
立即報名
尚未有邦友回答
立即登入回答
iThome鐵人賽
參賽組數
902
組
團體組數
37
組
累計文章數
19847
篇
完賽人數
528
人
看影片追技術
看更多
{{ item.subject }}
{{ item.channelVendor }}
|
{{ formatDate(item.duration) }}
直播中
熱門tag
15th鐵人賽
16th鐵人賽
13th鐵人賽
14th鐵人賽
17th鐵人賽
12th鐵人賽
11th鐵人賽
鐵人賽
2019鐵人賽
javascript
2018鐵人賽
python
2017鐵人賽
windows
php
c#
linux
windows server
css
react
熱門問題
[Javascript] 非同步執行,如何延緩後面程式的處理 ??
FortiGate SSLVPN替代方案?
AARQ 通訊協議是?
SSLVPN 轉 IPSEC VPN 的問題
Dell or Asus 伺服器,哪牌比較好?
Dell or Asus Storage 或NAS,哪牌比較好?
將硬碟上的 EFI 分割區複製到固態硬碟後,ARM 架構的 Ubuntu Server 無法啟動
iT邦幫忙如何搜尋 關鍵字?
sdray vigor2927 sslvpn ip設定問題
Qnap帳號於同一個IP反覆登入失敗.
熱門回答
FortiGate SSLVPN替代方案?
[Javascript] 非同步執行,如何延緩後面程式的處理 ??
Dell or Asus 伺服器,哪牌比較好?
將硬碟上的 EFI 分割區複製到固態硬碟後,ARM 架構的 Ubuntu Server 無法啟動
iT邦幫忙如何搜尋 關鍵字?
熱門文章
c++的.h和cpp,放在相同目錄下好,還是頂層就用include,src分開好? [搬運/問答]
人工智慧模型 LLM (單一模型) 與 人工智慧代理 AI Agent(人工智慧代理)是什麼?兩者之間的關鍵差異?
別再只是做報表了,真正的人資資料分析是這樣做的
你的產品用了多少開源軟體?如何掌握潛在漏洞與風險?
AI 音樂創作指令(Prompt)深度指南:解鎖主流AI 音樂生成工具的全部潛力
IT邦幫忙
×
標記使用者
輸入對方的帳號或暱稱
Loading
找不到結果。
標記
{{ result.label }}
{{ result.account }}