• C语言实现字母接龙的小程序


    代码
    #include<stdio.h>
    #include
    <stdlib.h>
    #include
    <time.h>
    main()
    {
    int i,j,c,flag,sign,counter;
    int array[10][10],area,x,y;
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    array[i][j]
    =46;
    for(i=0;i<10;i++)
    {
    for(j=0;j<10;j++)
    printf(
    "%c",array[i][j]);
    printf(
    "\n");
    }
    srand((unsigned)time(NULL));
    printf(
    "Notion!While the value of x and y less than 10 and positive integret,\n"
    "Please the beginning place of the game (x,y):");
    scanf(
    "%d,%d",&x,&y);
    array[x][y]
    =65;
    for(c=66;c<=90;c++)
    {
    do
    {
    counter
    =rand()%4;
    switch(counter)
    {
    case 0: /* Moving toward right*/
    {
    if(array[x][y+1]==46&&y+1<10)
    {
    array[x][
    ++y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }

    /* Moving toward down*/
    case 1:
    {
    if(array[x+1][y]==46&&x+1<10)
    {
    array[
    ++x][y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    /* Moving toward left*/
    case 2:
    {
    if(array[x][y-1]==46&&y-1>0)
    {
    array[x][
    --y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    /* Moving toward up*/
    case 3:
    {
    if(array[x-1][y]==46&&x-1>0)
    {
    array[
    --x][y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    }
    }
    while(flag!=1);
    flag
    =0;
    sign
    =(array[x][y+1]==46||array[x][y-1]==46||array[x-1][y]==46||array[x+1][y]==46);
    if(sign==0)
    break;
    }

    for(i=0;i<10;i++)
    {
    for(j=0;j<10;j++)
    printf(
    "%c",array[i][j]);
    printf(
    "\n");
    }
    getch();
    }
  • 相关阅读:
    python 装饰器
    python 环境迁移之requirements.txt (window环境)
    selenium 元素查找与属性
    pytest+allure(allure-pytest基于这个插件)设计定制化报告
    Capability配置
    python_excel
    python_连接mysql
    MySql_1
    appium_环境搭建
    appium_appium简介
  • 原文地址:https://www.cnblogs.com/uestc/p/1910903.html
Copyright © 2020-2023  润新知