C语言 电梯函数
#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语言 电梯函数的更多相关文章
- C语言pow函数编写
C语言pow函数编写 #include<stdio.h> double chaoba(double f,double q); //声明自定义函数 void main(void) { dou ...
- C语言-自定义函数
C语言自定义函数 --1-- 自定义函数定义 1.1 无参无返回值函数 1.2 无参有返回值函数 1.3 有参无返回值函数 1.4 有参有返回值函数 --2-- 函数的参数 2.1 形式参数介绍和使用 ...
- C语言printf()函数:格式化输出函数
C语言printf()函数:格式化输出函数 头文件:#include <stdio.h> printf()函数是最常用的格式化输出函数,其原型为: int printf( char ...
- C语言的函数
"函数"在英文的翻译是"function",无论在自然科学还是计算机科学都是这个词,而"function"的本意是"功能" ...
- c语言main函数返回值、参数详解(返回值是必须的,0表示正常退出)
C语言Main函数返回值 main函数的返回值,用于说明程序的退出状态.如果返回0,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...
- Go语言示例-函数返回多个值
Go语言中函数可以返回多个值,这和其它编程语言有很大的不同.对于有其它语言编程经验的人来说,最大的障碍不是学习这个特性,而是很难想到去使用这个特性. 简单如交换两个数值的例子: package mai ...
- 【学习笔记】【C语言】函数
一. 什么是函数 任何一个C语言程序都是由一个或者多个程序段(小程序)构成的,每个程序段都有自己的功能,我们一般称这些程序段为“函数”.所以,你可以说C语言程序是由函数构成的. 比如你用C语言编写了一 ...
- 【转载】 c语言inline函数的使用
c语言inline函数的使用 转载自:http://blog.chinaunix.net/uid-21843265-id-3056446.html 大学在教科书上学习过inline函数,定义为inli ...
- 【C语言】函数和自定义函数
函数,我之前也提到过一点点内容.其实函数是很好理解的,但是写起来又十分麻烦. 一. 函数引入 我们知道,C源程序是由函数组成的.请看下面的简单函数例子 #include <stdio.h ...
随机推荐
- Android实现数据存储技术
转载:Android实现数据存储技术 本文介绍Android中的5种数据存储方式. 数据存储在开发中是使用最频繁的,在这里主要介绍Android平台中实现数据存储的5种方式,分别是: 1 使用Shar ...
- 在Shell中使用函数文件
需要编写一个较庞大的脚本时,可能会涉及许多函数.变量.这是通常建议将众多的函数.变量放入一个单独的脚本内.这样做的好处很明显,不用担心某个函数.变量是否已经被定义和使用,也不用频繁地定义.清除函数和变 ...
- Thrift安装问题
1.error: Bison version 2.5 or higher must be installed on the system! 哈哈,Bison版本低了吧,用下面的命令 wget ht ...
- SQL Server 中的事务和锁(三)-Range S-U,X-X 以及死锁
在上一篇中忘记了一个细节.Range T-K 到底代表了什么?Range T-K Lock 代表了在 SERIALIZABLE 隔离级别中,为了保护范围内的数据不被并发的事务影响而使用的一类锁模式(避 ...
- Python练习题 028:求3*3矩阵对角线数字之和
[Python练习题 028] 求一个3*3矩阵对角线元素之和 ----------------------------------------------------- 这题解倒是解出来了,但总觉得 ...
- solr查询在solrconfig.xml中的配置
<requestHandler name="/select" class="solr.SearchHandler"> <lst name=&q ...
- python使用rrdtool时 argument 0 must be string的问题
在updatev rrdfile时, ret = rrdtool.updatev(filename, ds) 报了argument 0 must be string的异常,经查是因为python 的r ...
- 【转】ViewGroup的onMeasure和onLayout分析
ViewGroup的onMeasure和onLayout分析 一个Viewgroup基本的继承类格式如下: 1 import android.content.Context; 2 import and ...
- hdu 4411 最小费用流
思路:主要就是要把一个每个城市拆为两个点,建一条容量为1,费用为-inf的边,保证每个城市都会被遍历. /*最小费用最大流*/ #include<iostream> #include< ...
- Ajax+JSON学习笔记(二)
来源:http://www.imooc.com/learn/250 readyState属性 0:请求未初始化,open还没有调用 1:服务器连接已建立,open已经调用了 2:请求已接受,也就是接收 ...