iT邦幫忙

0

這C語言的程式碼那些地方出錯?

看更多先前的討論...收起先前的討論...
程式碼的部分請改成下方這樣子:
```c
程式碼
```
vuj8104 iT邦新手 5 級 ‧ 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++);
}
}
vuj8104 iT邦新手 5 級 ‧ 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++);
}
}
```
vuj8104 iT邦新手 5 級 ‧ 2020-10-04 11:39:48 檢舉
怎麼用啊?我不會抱歉
修改文章,程式碼前後加上去
vuj8104 iT邦新手 5 級 ‧ 2020-10-04 14:16:07 檢舉
重新發問了
https://ithelp.ithome.com.tw/m/questions/10200536

尚未有邦友回答

立即登入回答