博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C语言 电梯函数
阅读量:7235 次
发布时间:2019-06-29

本文共 2707 字,大约阅读时间需要 9 分钟。

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

void test(){//汉字输出

    printf("THIS IS TEST\n");

    printf("My age is %d\n",26);

    printf("My age is %4d  发现没?26前面多了两个空格\n",26);

    printf("My age is %d,heighe is %f,name is %s,sex is %c\n",26,1.55,"李明杰",'A' );//双引号字符串(汉字属于字符串)用S,单引号字符用C

    printf("My age is %d,heighe is %.2f,name is %s,sex is '%c'\n",26,1.55,"李明杰",'A' );// %.2f代表2位小数,'%c'输出时才会带上单引号,输出不会帮你单上单引号的

    printf("sex is %s\n","男");

 

}

 

void test1(){//?:条件语句运用

    printf("THIS IS TEST1\n");

    int a,b,c;

    scanf("%d %d %d",&a,&b,&c);

    int d=(a>b?a:b)>(c)?(a>b?a:b):(c);

    printf("%d\n",d);

}

 

 

void test2(){//电梯函数

    printf("THIS IS TEST2\n");

    int z=1,b,c;//默认为了TEST1中的第一个输入的数。

leap: {

       printf("Welcome to take the elevator\ninput the floor you want to go,please...\n");

    scanf("%d",&c);

    srand((unsigned int)time(0));

    b=rand()%103+1;//产生客户所在层数

    printf("You are located in the first layer of %d,now.\n You will go to the %d layer\n The elevator is now located in the first layer of %d\n Wait a moment,please...\n",b,c,z);

    if (z>b)

    {//电梯靠近

        for (int i=1; i<=z-b; i++)

        {

            printf("%d\n",z-i);

        }

    }

    else if (z<b){

        for (int i=1; i<=b-z; i++)

        {

            printf("%d\n",z+i);

        }

    }

    else{

        printf("电梯就在这一层\n");

    }

    printf("将要开门,请注意安全!!!\n");//开关门函数

    printf("将要关门,请注意安全!!!\n");

    if (b>c)//乘坐电梯到达目的地

    {

        for (int i=1; i<=b-c; i++)

        {

            printf("%d\n",b-i);

        }

    }

    else if (b<c){

        for (int i=1; i<=c-b; i++)

        {

            printf("%d\n",b+i);

        }

    }

    else{

        printf("电梯就在这一层,你运气真好");

    }

    printf("将要开门,请注意安全!!!\n欢迎你再次乘坐\n");//开关门函数

    printf("将要关门,请注意安全!!!\n");

    z=c;//让程序记住当前电梯所在楼层

}

    goto leap;

}

 

void test3(){//电梯函数已解决

    printf("THIS IS TEST3\n");

    int a=1,b,c;//默认为了TEST1中的第一个输入的数。

    printf("恭喜你成为此程序此次运行的第一个乘客!!!!\n");

leap: {

    printf("Welcome to take the elevator\ninput the floor you want to go,please...\n");

    scanf("%d",&c);

    if (c>103) {

        printf("输入错误!!!\n请重新输入\n");

    }

    else {

    srand((unsigned int)time(0));

    b=rand()%103+1;//产生客户所在层数

    printf("You are located in the first layer of %d,now.\n You will go to the %d layer\n The elevator is now located in the first layer of %d\n Wait a moment,please...\n",b,c,a);

    if (a>b)

    {//电梯靠近

        for (int i=1; i<=a-b; i++)

        {

            printf("%d\n",a-i);

        }

    }

    else if (a<b){

        for (int i=1; i<=b-a; i++)

        {

            printf("%d\n",a+i);

        }

    }

    else{

        printf("电梯就在这一层\n");

    }

    printf("将要开门,请注意安全!!!\n");//开关门函数

    printf("将要关门,请注意安全!!!\n");

    if (b>c)//乘坐电梯到达目的地

    {

        for (int i=1; i<=b-c; i++)

        {

            printf("%d\n",b-i);

        }

    }

    else if (b<c){

        for (int i=1; i<=c-b; i++)

        {

            printf("%d\n",b+i);

        }

    }

    else{

        printf("电梯就在这一层,你运气真好");

    }

    printf("将要开门,请注意安全!!!\n欢迎你再次乘坐\n");//开关门函数

    printf("将要关门,请注意安全!!!\n");

    a=c;

    }

}

    goto leap;

}int main(int argc, const char * argv[]) {

    

    printf("Hello, World!\n");

    test();

    test1();

    test2();//已解决电梯停留层数随机。

    test3();//已解决不记录当前楼层问题。

    return 0;

}

转载于:https://www.cnblogs.com/OIMM/p/4695712.html

你可能感兴趣的文章
跟小菜学虚拟化,之Microsoft Hyper-v 学习笔记(一)
查看>>
静态数据成员
查看>>
继LINQ动态组合查询PredicateExtensions讲解
查看>>
使用zabbix discovery监控网卡百兆
查看>>
mysql连接小错误一例
查看>>
Flash持续集成自动化单元测试
查看>>
oracle一点资料
查看>>
28个实用的源码/文档比较合并工具
查看>>
js的cookie操作
查看>>
Nginx 域名跳转配置
查看>>
ASP.NET MVC扩展库
查看>>
pyodbc简单使用
查看>>
数据库厂商提供的 Providers for ASP.NET
查看>>
memcached演练(5) 内存管理
查看>>
烂泥:Windows server 2008开启远程桌面
查看>>
烂泥:IE10浏览器兼容模式
查看>>
我的家庭私有云计划-21
查看>>
Windows10-加速在企业中的部署
查看>>
综合应用WPF/WCF/WF/LINQ之三十八:实现一个简单的DataGrid之总体介绍
查看>>
Variant类型在各语言中的参数传递
查看>>