#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;

}

C语言 电梯函数的更多相关文章

  1. C语言pow函数编写

    C语言pow函数编写 #include<stdio.h> double chaoba(double f,double q); //声明自定义函数 void main(void) { dou ...

  2. C语言-自定义函数

    C语言自定义函数 --1-- 自定义函数定义 1.1 无参无返回值函数 1.2 无参有返回值函数 1.3 有参无返回值函数 1.4 有参有返回值函数 --2-- 函数的参数 2.1 形式参数介绍和使用 ...

  3. C语言printf()函数:格式化输出函数

    C语言printf()函数:格式化输出函数 头文件:#include <stdio.h> printf()函数是最常用的格式化输出函数,其原型为:     int printf( char ...

  4. C语言的函数

    "函数"在英文的翻译是"function",无论在自然科学还是计算机科学都是这个词,而"function"的本意是"功能" ...

  5. c语言main函数返回值、参数详解(返回值是必须的,0表示正常退出)

    C语言Main函数返回值 main函数的返回值,用于说明程序的退出状态.如果返回0,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...

  6. Go语言示例-函数返回多个值

    Go语言中函数可以返回多个值,这和其它编程语言有很大的不同.对于有其它语言编程经验的人来说,最大的障碍不是学习这个特性,而是很难想到去使用这个特性. 简单如交换两个数值的例子: package mai ...

  7. 【学习笔记】【C语言】函数

    一. 什么是函数 任何一个C语言程序都是由一个或者多个程序段(小程序)构成的,每个程序段都有自己的功能,我们一般称这些程序段为“函数”.所以,你可以说C语言程序是由函数构成的. 比如你用C语言编写了一 ...

  8. 【转载】 c语言inline函数的使用

    c语言inline函数的使用 转载自:http://blog.chinaunix.net/uid-21843265-id-3056446.html 大学在教科书上学习过inline函数,定义为inli ...

  9. 【C语言】函数和自定义函数

    函数,我之前也提到过一点点内容.其实函数是很好理解的,但是写起来又十分麻烦. 一.     函数引入 我们知道,C源程序是由函数组成的.请看下面的简单函数例子 #include <stdio.h ...

随机推荐

  1. CGI,FastCGI,PHP-CGI与PHP-FPM(转)

    http://www.cnblogs.com/zl0372/articles/php_4.html CGI CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服 ...

  2. 构建高性能服务(三)Java高性能缓冲设计 vs Disruptor vs LinkedBlockingQueue--转载

    原文地址:http://maoyidao.iteye.com/blog/1663193 一个仅仅部署在4台服务器上的服务,每秒向Database写入数据超过100万行数据,每分钟产生超过1G的数据.而 ...

  3. Toad for Oracle 授权权限

    grant create session to 用户;//授予zhangsan用户创建session的权限,即登陆权限 grant dba to 用户; //授权dba权限,导入导出数据 grant ...

  4. C#中的多态现象

    面向对象的特征封装.继承和多态.Polymorphism(多态性)来源于希腊单词,指“多种形态”.多态性的一个重要特征是方法的调用是在运行时确定而不是编译时.在.NET中用于实现多态性的关键词有vir ...

  5. Easier Done Than Said?

    Problem Description Password security is a tricky thing. Users prefer simple passwords that are easy ...

  6. Java中ThreadLocal的设计与使用

    早在Java 1.2推出之时,Java平台中就引入了一个新的支持:java.lang.ThreadLocal,给我们在编写多线程程序时提供了一种新的选择.使用这个工具类可以很简洁地编写出优美的多线程程 ...

  7. 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码

    来自:http://www.cnblogs.com/lcxu2/archive/2011/01/16/2004016.html 正试图在 os 加载程序锁内执行托管代码.不要尝试在 DllMain 或 ...

  8. linux初学 :简易的shell脚本

    什么是shell Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的 Shell有两种执行命令的方式: 交互式(Interacti ...

  9. Java跳出循环-break和continue语句

    在实际编程中,有时需要在条件语句匹配的时候跳出循环.在Java里,由break和continue语句控制. “break”语句 “break”语句用来结束循环,即不再执行后边的所有循环. 示例:计算1 ...

  10. ORA-01034: 、ORA-01078: 和 LRM-00109: 的解决方法

    环境:Linux 5.4 Oracle 11.2.0.3 在Linux上连接Oracle时遇到报错: SQL> show parameter sgaORA-01034: ORACLE not a ...