#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void test(){//汉字输出
printf("THIS IS TEST ");
printf("My age is %d ",26);
printf("My age is %4d 发现没?26前面多了两个空格 ",26);
printf("My age is %d,heighe is %f,name is %s,sex is %c ",26,1.55,"李明杰",'A' );//双引号字符串(汉字属于字符串)用S,单引号字符用C
printf("My age is %d,heighe is %.2f,name is %s,sex is '%c' ",26,1.55,"李明杰",'A' );// %.2f代表2位小数,'%c'输出时才会带上单引号,输出不会帮你单上单引号的
printf("sex is %s ","男");
}
void test1(){//?:条件语句运用
printf("THIS IS TEST1 ");
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 ",d);
}
void test2(){//电梯函数
printf("THIS IS TEST2 ");
int z=1,b,c;//默认为了TEST1中的第一个输入的数。
leap: {
printf("Welcome to take the elevator input the floor you want to go,please... ");
scanf("%d",&c);
srand((unsigned int)time(0));
b=rand()%103+1;//产生客户所在层数
printf("You are located in the first layer of %d,now. You will go to the %d layer The elevator is now located in the first layer of %d Wait a moment,please... ",b,c,z);
if (z>b)
{//电梯靠近
for (int i=1; i<=z-b; i++)
{
printf("%d ",z-i);
}
}
else if (z<b){
for (int i=1; i<=b-z; i++)
{
printf("%d ",z+i);
}
}
else{
printf("电梯就在这一层 ");
}
printf("将要开门,请注意安全!!! ");//开关门函数
printf("将要关门,请注意安全!!! ");
if (b>c)//乘坐电梯到达目的地
{
for (int i=1; i<=b-c; i++)
{
printf("%d ",b-i);
}
}
else if (b<c){
for (int i=1; i<=c-b; i++)
{
printf("%d ",b+i);
}
}
else{
printf("电梯就在这一层,你运气真好");
}
printf("将要开门,请注意安全!!! 欢迎你再次乘坐 ");//开关门函数
printf("将要关门,请注意安全!!! ");
z=c;//让程序记住当前电梯所在楼层
}
goto leap;
}
void test3(){//电梯函数已解决
printf("THIS IS TEST3 ");
int a=1,b,c;//默认为了TEST1中的第一个输入的数。
printf("恭喜你成为此程序此次运行的第一个乘客!!!! ");
leap: {
printf("Welcome to take the elevator input the floor you want to go,please... ");
scanf("%d",&c);
if (c>103) {
printf("输入错误!!! 请重新输入 ");
}
else {
srand((unsigned int)time(0));
b=rand()%103+1;//产生客户所在层数
printf("You are located in the first layer of %d,now. You will go to the %d layer The elevator is now located in the first layer of %d Wait a moment,please... ",b,c,a);
if (a>b)
{//电梯靠近
for (int i=1; i<=a-b; i++)
{
printf("%d ",a-i);
}
}
else if (a<b){
for (int i=1; i<=b-a; i++)
{
printf("%d ",a+i);
}
}
else{
printf("电梯就在这一层 ");
}
printf("将要开门,请注意安全!!! ");//开关门函数
printf("将要关门,请注意安全!!! ");
if (b>c)//乘坐电梯到达目的地
{
for (int i=1; i<=b-c; i++)
{
printf("%d ",b-i);
}
}
else if (b<c){
for (int i=1; i<=c-b; i++)
{
printf("%d ",b+i);
}
}
else{
printf("电梯就在这一层,你运气真好");
}
printf("将要开门,请注意安全!!! 欢迎你再次乘坐 ");//开关门函数
printf("将要关门,请注意安全!!! ");
a=c;
}
}
goto leap;
}int main(int argc, const char * argv[]) {
printf("Hello, World! ");
test();
test1();
test2();//已解决电梯停留层数随机。
test3();//已解决不记录当前楼层问题。
return 0;
}