一个c语言问题,编译通过但不能运行

来源:百度知道 编辑:UC知道 时间:2024/05/29 02:05:58
题目:
Random Walk(随机行走). 编写程序产生贯穿10x10数组的”随机步”. 初始时数组元素为’.’. 程序必须从一个元素随机“走到”另一个元素. 对一个元素来说这种走始终向上、向下、向左或向右. 程序访问到的元素用从A到Z的字母进行标记, 而且按顺序进行访问.
提示:使用srand和rand产生随机数, 然后查看此数除以4的余数, 共有4种可能的值: 0, 1, 2, 3,这些数字说明了下一次移动的方向. 在执行移动之前需要检查两项内容: 一是不能超出数组范围, 二是不要选取已经标记了字母的元素, 如果两个条件都不满足, 尝试换个方向移动, 如果全部锁定了下一步的4个方向,那么程序必须终止.

我编的程序:
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int go(){
int t,mo;
t=(int)(4*rand());
mo=t%4;
return mo;
}

int test(int up,int down,int left,int right,int t1){
switch (t1){
case 0:
if(up==1){
return 1;
}
case 1:
if(down==1){
return 1;
}
case 2:
if(left==1){
return 1;
}
case 3:
if(right==1){
return 1;
}
}
}

void main(){
char mat[12][12];
in

改好了 在下面已经注释
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int go(){
int t,mo;
t=(int)(4*rand());
mo=t%4;
return mo;
}

int test(int up,int down,int left,int right,int t1){
switch (t1){
case 0:
if(up==1){
return 1;
}
case 1:
if(down==1){
return 1;
}
case 2:
if(left==1){
return 1;
}
case 3:
if(right==1){
return 1;
}
}
return 0;
}

void main()
{
char mat[12][12];
int i,t,tgo,x,y,m,n,sum;
int up=1,down=1,left=1,right=1;
char s;
srand((unsigned) time(NULL));

for(m=1;m<11;m++){
for(n=1;n<11;n++){
mat[m][n]=46;
}
}

mat[1][1]=65;
x=0,y=0;

for (i=1;i<26;i++){
u