网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月12日漏签0天
c语言吧 关注:802,157贴子:4,378,365
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 2回复贴,共1页
<<返回c语言吧
>0< 加载中...

【海龟图】不知道哪儿错了。。编出来怪怪的。。。。求指导。。。

  • 只看楼主
  • 收藏

  • 回复
  • MrSwordsman
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
不多说了,直接放程序:
#include<stdio.h>
void getCommands(int commands[][2])
{
int i,n;
printf( "Enter command ( 9 to end input ): " );
scanf("%d",&n);
for(i=0;n!=9&&i<100;i++)
{
commands[i][0]=n;
if(n==5)
{
scanf(",%d",&commands[i][1]);
}
printf("\nEnter command ( 9 to end input ): " );
scanf("%d",&n);
i++;
}
commands[i][0]=9;
}
int turnRight( int d )
{
d ++;
if (d = 4)
d = 0;
return d;
}
int turnLeft( int d )
{
d --;
if (d = -1)
d = 3;
return d;
}
void movePen( int down, int a[][ 50 ], int dir, int dist)
{
int i;
static int x, y = 0;
for (i = 0; i < dist;i ++)
{
switch(dir)
{
case 0:
y = y + dist - 1;
if (down = 1)
a[x][y - i] = 1;
break;
case 1:
x = x + dist - 1;
if (down = 1)
a[x - i][y] = 1;
break;
case 2:
y = y - dist + 1;
if (down = 1)
a[x][y + i] = 1;
break;
case 3:
x = x - dist + 1;
if (down = 1)
a[x + i][y] = 1;
break;
}
}
}
void printArray( int a[][ 50 ] )
{
int i,j;
for (i = 0;i < 50;i ++)
{
for (j = 0;j < 50;j ++)
{
if (a[i][j] = 1)
printf("*");
else
printf(" ");
if (j = 49)
printf("\n");
}
}
}
int main()
{
int command,dist;
int commands[100][2];
int floor[50][50]={0};
int k=0;
int pendown;
int direction = 0;
printf("****************************************\n");
printf("* 1:penUp 2:penDown *\n");
printf("* 3:turnRight 4:turnLeft *\n");
printf("* 5:move 6:print *\n");
printf("* 9:end *\n");
printf("****************************************\n");
getCommands(commands);
command=commands[0][0];
while(command!=9)
{
switch(command)
{
case 1:
pendown=0;
break;
case 2:
pendown=1;
break;
case 3:
direction=turnRight(direction);
break;
case 4:
direction=turnLeft(direction);
break;
case 5:
dist = commands[k][1];
movePen(pendown, floor,direction,dist );
break;
case 6:
printArray( floor);
break;
} k++;
command=commands[k][0];
}
return 0;
}


  • MrSwordsman
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
比如当我想输出一个12*12的正方形时,输出来的是这样的:


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 2回复贴,共1页
<<返回c语言吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示