mly8410112 于 2014.09.25 10:46 提问

Code Blocks 下C语言编程的问题

enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}
enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}

enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}

1个回答

u013648963   2014.09.28 01:05