这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 高校专区 » 岭南EE码农港 » C语言课程设计—龟兔赛跑

共4条 1/1 1 跳转至

C语言课程设计—龟兔赛跑

菜鸟
2014-11-21 13:39:45     打赏
 

#include<stdio.h>

    #include<stdlib.h>

    #include<time.h>

    #include<Windows.h>

    void guitu (void);

    main()

{

    srand(time(NULL));

       guitu();

       return 0;

      

}

    void guitu()

    {

       int j,count=0,cou=0,number;

       char printfun[71];

       while(1)

       {

           for(j=0;j<70;j++)

           {

              printfun[j]=' ';

              printfun[70]='|';

           }

           number=rand()%10+1;

           printf("\n");

           if( number>=1&&number<=5)

           {

              count+=3;

              if(count>70)

              {

                  count=0;

              }

              printfun[count]='G';

           }

           if(number>=6&&number<=7)

           {

              count-=6;

              if(count<0)

              {

                  count=0;

              }

              printfun[count]='G';

           }

           if(number>=8&&number<=10)

           {

              count+=1;

              if(count>70)

              {

                  count=0;

              }

              printfun[count]='G';

           }

           if(number>=1 && number<=2)

           {

              cou+=0;

              if(cou>70)

              {

                  cou=0;

              }

              printfun[cou]='T';

           }

           if(number>=3 && number<=4)

           {

              cou+=9;

              if(cou>70)

              {

                  cou=0;

              }

              printfun[cou]='T';

           }

           if(cou==5)

       {

              cou-=12;

              if(cou<0)

              {

                  cou=0;

              }

              printfun[cou]='T';

       }

           if(number>=6 && number<=8)

           {

              cou+=1;

              if(cou<70)

              {

                  cou=0;

              }

              printfun[cou]='T';

           }

           if(number>=9 && number<=10)

           {

              cou-=2;

              if(cou<0)

              {

                  cou=0;

              }

              printfun[cou]='T';

           }

           if(count==cou)

           {

              printfun[count]='P';

           }

           printf("%s\n",printfun);

           printf("\n");

           if(count==70)

           {

              printf("gui win ! ! ! \n");

              break;

           }

           if(cou==70)

           {

              printf("tui win ! ! !\n");

              break;

           }

          

       }

    }

   

  总结:敲打程序时,一定要认真,决不能有半点马虎,尤其是在做一些比较复杂的程序时,因为逻辑性比较强,所以我们一定要更加认真对待。    

      

      

      

   


院士
2014-11-21 14:05:11     打赏
2楼

看样子留的作业就是龟兔赛跑

 

和楼主说一句,EEPW论坛是带有代码功能的,参考第一行的C#


菜鸟
2014-11-26 19:34:00     打赏
3楼
不是龟兔赛跑的作业,就是大家的想象力太limit了,自由作业

菜鸟
2014-11-26 19:34:47     打赏
4楼
if如果只有一句的话,可以不要加括号

共4条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]