C-language Elevator function

Source: Internet
Author: User

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

void Test () {//Kanji output

printf ("This is test\n");

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

printf ("My age is%4d found?") 26 more than two spaces in front \ n ", 26);

printf ("My age is%d,heighe are%f,name is%s,sex is%c\n", 26, 1.55, "Li Mingjie", ' A ');//double-quoted string (Chinese character belongs to string) with S, single quote character with C

printf ("My age is%d,heighe are%.2f,name is%s,sex are '%c ' \ n", 26, 1.55, "Li Mingjie", ' A '),//%.2f represents 2 decimal places, '%c ' is output with single quotes, the output will not help you single-lead Number of

printf ("Sex is%s\n", "male");

}

void Test1 () {///?: Conditional statements Apply

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 () {//Elevator function

printf ("This is test2\n");

int z=1,b,c;//defaults to the number of the first input in TEST1.

Leap: {

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

scanf ("%d", &c);

Srand ((unsigned int) time (0));

B=rand ()%103+1;//generate the number of layers of the customer

printf ("You were located in the first layer of%d,now.\n you'll go to the%d layer\n the elevator was now located in the F Irst layer of%d\n Wait a moment,please...\n ", b,c,z);

if (z>b)

{//Elevator close

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 ("Lift is on this floor \ n");

}

printf ("will open the door, please pay attention to the safety!!! \ n ");//open-close function

printf ("will be closed, please pay attention to safety!!! \ n ");

if (b>c)//Take the elevator to reach the destination

{

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 ("The elevator is on this floor, you're lucky");

}

printf ("will open the door, please pay attention to the safety!!! \ \ \ \ \ \ \ n welcome you again.

printf ("will be closed, please pay attention to safety!!! \ n ");

z=c;//Let the program remember the current floor of the elevator

}

Goto Leap;

}

void Test3 () {//Elevator function resolved

printf ("This is test3\n");

int a=1,b,c;//defaults to the number of the first input in TEST1.

printf ("Congratulations on being the first passenger to run this program!!!! \ n ");

Leap: {

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

scanf ("%d", &c);

if (c>103) {

printf ("Input error!!! \ n Please re-enter \ n ");

}

else {

Srand ((unsigned int) time (0));

B=rand ()%103+1;//generate the number of layers of the customer

printf ("You were located in the first layer of%d,now.\n you'll go to the%d layer\n the elevator was now located in the F Irst layer of%d\n Wait a moment,please...\n ", b,c,a);

if (a>b)

{//Elevator close

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 ("Lift is on this floor \ n");

}

printf ("will open the door, please pay attention to the safety!!! \ n ");//open-close function

printf ("will be closed, please pay attention to safety!!! \ n ");

if (b>c)//Take the elevator to reach the destination

{

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 ("The elevator is on this floor, you're lucky");

}

printf ("will open the door, please pay attention to the safety!!! \ \ \ \ \ \ \ n welcome you again.

printf ("will be closed, please pay attention to safety!!! \ n ");

A=c;

}

}

Goto Leap;

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

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

Test ();

Test1 ();

Test2 ();//resolved elevator dwell layer random.

Test3 ();//resolved not to log current floor issues.

return 0;

}

C-language Elevator function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.