c语言的最简单的实际运用

#include <stdio.h>
#include <conio.h> 
int main(void)
{
  int player = 0;                      /* Player number - 1 or 2               */
  int winner = 0;                      /* The winning player                   */
  int choice = 0;                      /* Square selection number for turn     */
  int row = 0;                         /* Row index for a square               */
  int column = 0;                      /* Column index for a square            */
  int line=0;                          /* Row or column index in checking loop */

  char board[3][3] = {                 /* The board */
              {'1','2','3'},           /* Initial values are reference numbers */
              {'4','5','6'},           /* used to select a vacant square for   */
              {'7','8','9'}            /* a turn.                              */
                     };

  /* The main game loop. The game continues for up to 9 turns */
  /* As long as there is no winner                            */
  for(int i = 0; i<9 && winner==0; i++)
  {
    /* Display the board */
    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("---+---+---\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
     printf("---+---+---\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

    player = i%2 + 1;                 /* Select player */

    /* Get valid player square selection */
    do
    {
      printf("\nPlayer %d, please enter the number of the square "
             "where you want to place your %c: ",
              player,(player==1)?'X':'O');
      scanf("%d", &choice);

      row = --choice/3;                /* Get row index of square    */
      column = choice%3;               /* Get column index of square */
    }while(choice<0 || choice>9 || board[row][column]>'9');
int x,y,m,n;
   int k = 0;
   char q;
   printf("1代表石头;2代表剪刀;3代表布;\n");
   printf("请输入您的选择.\n");
   while(k<3)
   {
    scanf("%d", &y);
       k++;
       game(y,x);
   }
   result(m,n);
   system("pause");
   return 0;

  http://www.suopao.org/read-htm-tid-3306348.html

  http://www.suopao.org/read-htm-tid-3306352.html

  http://www.suopao.org/read-htm-tid-3306374.html

  http://www.suopao.org/read-htm-tid-3306375.html

  http://www.suopao.org/read-htm-tid-3306376.html

  http://www.suopao.org/read-htm-tid-3306377.html

  http://www.suopao.org/read-htm-tid-3306378.html

  http://www.suopao.org/read-htm-tid-3306379.html

  http://www.suopao.org/read-htm-tid-3306380.html

  http://www.suopao.org/read-htm-tid-3306381.html

  http://www.suopao.org/read-htm-tid-3306382.html

  http://www.suopao.org/read-htm-tid-3306383.html

  http://www.suopao.org/read-htm-tid-3306384.html

  http://www.suopao.org/read-htm-tid-3306385.html

  http://www.suopao.org/read-htm-tid-3306386.html

  http://www.suopao.org/read-htm-tid-3306387.html

  http://www.suopao.org/read-htm-tid-3306388.html

  http://www.suopao.org/read-htm-tid-3306389.html

  http://www.suopao.org/read-htm-tid-3306390.html

  http://www.suopao.org/read-htm-tid-3306391.html

  http://www.suopao.org/read-htm-tid-3306392.html

  http://t.163.com/event/info/eventId/-2052780540698412395

  http://t.163.com/event/info/eventId/-5182265387755694935

  http://t.163.com/event/info/eventId/3027986030813966823

  http://blog.1688.com/article/i36672409.html

  http://blog.1688.com/article/i36672436.html

  http://blog.1688.com/article/i36672457.html

  http://blog.1688.com/article/i36672486.html

  http://blog.1688.com/article/i36672501.html

  http://blog.1688.com/article/i36672515.html

  http://blog.1688.com/article/i36672527.html

  http://blog.1688.com/article/i36672536.html

  http://blog.1688.com/article/i36672552.html

  http://www.suopao.org/read-htm-tid-3306349.html

  http://www.suopao.org/read-htm-tid-3306350.html

  http://www.huihui.cn/share/31297148

  http://www.huihui.cn/share/31295094

  http://www.huihui.cn/share/31299252

  http://www.huihui.cn/share/31298258

  http://yun.baidu.com/share/link?shareid=4190492627&uk=2668634217&third=0

  http://pan.baidu.com/s/1i32xflN

  http://pan.baidu.com/s/1c0Ec6C4

  http://pan.baidu.com/s/1pJLNEd1

  http://pan.baidu.com/s/1mgNpEVA

  http://pan.baidu.com/s/1qWEuddy

  http://pan.baidu.com/s/1ntAwwY1

  http://pan.baidu.com/s/1sj545Pj

  http://wenwen.soso.com/z/q530083564.htm

  http://wenwen.soso.com/z/q530083590.htm

} int game(int y,int x) { int m = 0; //玩家赢的次数 int n = 0; //电脑赢的次数 srand(time(NULL)); x = rand()%3+1; //取随机数1~3 if(y==1&&x==3) { printf("你出石头\n"); printf("电脑出布\n"); printf("你输了\n"); ++n; //电脑赢的次数 } else if(y==1&&x==1) { printf("大家都出石头,平局\n"); ++m; ++n; } else if(y==1&&x==2) { printf("你出石头\n"); printf("电脑出剪刀\n"); printf("你赢了\n"); ++m; //玩家赢的次数 } if(y==2&&x==1) { printf("你出剪刀\n"); printf("电脑出石头\n"); printf("你输了\n"); ++n; } else if(y==2&&x==2) { printf("大家都出剪刀,平局\n"); ++m; ++n; } else if(y==2&&x==3) { printf("你出剪刀\n"); printf("电脑出布\n"); printf("你赢了\n"); ++m; } if(y==3&&x==1) { printf("你出布\n"); printf("电脑石头\n"); printf("你赢了\n"); ++m; } else if(y==3&&x==2) { printf("你出石头\n"); printf("电脑出剪刀\n"); printf("你输了\n"); ++n; } else if(y==3&&x==3) { printf("大家都出布,平局\n"); ++m; ++n; } return m,n; //返回m,n的值 } int result(int m,int n) //比较最终结果 { if(m<n) printf("3局%d胜,你输了.\n",m); else if(m>n) printf("3局%d胜,你赢了.\n",m); else if(m==n) printf("一胜一负一平局,旗鼓相当。\n"); return 0;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值