3. Select structure program design and structure program design.

Source: Internet
Author: User

3. Select structure program design and structure program design.

The if statement is used to implement the selection structure (with a range) of two branches. The switch statement is used to implement the selection structure of multiple branches (preferably a fixed value)

For example

// Condition branch if // int num1 = 20; // int num2 = 10; // if (num1> num2) // {// printf ("num1> num2 \ n ");//}//

Multiple if

// Multiple if ...... else if ..... else. // float score; // printf ("Enter the score \ n"); // scanf ("% f", & score ); //// if (score> = 90) & (score <= 100) {printf ("Excellent \ n "); ///} else if (score> = 80) & (score <90) {printf ("good \ n ");} // else if (score> = 60) & (score <70) {printf ("Medium \ n ");} // else {printf ("difference \ n ");////}

Switch statement

Enter the number of days in the year/month Query

// Int year, month; // printf ("Enter year: \ n"); // scanf ("% d", & year ); // printf ("Enter the month: \ n"); // scanf ("% d", & month); // switch (month) {// case 1: // case 3: // case 5: // case 7: // case 8: // case 10: // case 12: // printf ("31 days this month \ n"); // break; // case 4: // case 6: // case 9: // case 11: // printf ("30 days this month \ n"); // break; // case 2: /// if (year % 4 = 0 & year % 100! = 0) | (year % 400 = 0) {// printf ("this month is 29 days of the leap year \ n "); //} else {// printf ("this month is 28 days of the year \ n"); //} // break; // default: printf ("the month you entered is incorrect \ n"); // break ;//}////

Query for vowels

// Char a; // printf ("Enter the letter \ n"); // scanf ("% c", & a); // switch () {// case 'A': // case 'E': // case 'I': // case 'O': // case 'U ': // case 'A': // case 'E': // case 'I': // case 'O': // case 'U ': // printf ("it is a vowel letter \ n"); // break; // default: printf ("not a vowel letter \ n"); // break; //}//

Arithmetic Operation

// Result indicates the first number, the second number, and the fourth number of operands. // The second number, the second number, and the second number of operands. // int result = 0, num1, num2; // char success; // int flag = 1; // printf ("enter two numbers \ n"); // scanf ("% d ", & num1, & num2); // printf ("Please input the operand :( +,-, *,/) \ n"); // scanf ("% c ", & Environment); // switch (Environment) {// case '+': // result = num1 + num2; // break; // case '-': // result = num1-num2; // break; // case '*': // result = num1 * num2; // break; // case '/': // result = num1/num2 ;// Break; // default: // flag = 0; // break; //} // if (flag = 1) {// printf ("result = % d \ n", result); //} // else // {// printf ("your input is incorrect! \ N ");//}

 

 

 

You can see it later.

 

 

 

 

 

 

// Question 6 // float x, y; // printf ("Enter the value of x \ n"); // scanf ("% f", & x ); // if (x <1) {// printf ("Y value: %. 2f \ n ", y = x); //} else if (1 <= x & x <10) // {printf (" Y value: %. 2f \ n ", y = 2 * x-1); //} // else {// printf (" the value of Y is: %. 2f \ n ", y = 3 * X-11); // question 7 // float gz, grs, g; // printf ("Enter your salary \ n"); // scanf ("% f", & g); // gz = g-300-3500; // if (g> 0) {// if (gz> 0 & gz <= 1500) {// printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.03); //} else if (gz> 1500 & gz <= 4500) // {printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.1-105); //} else if (gz> 4500 & gz <= 9000) // {printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.2-555); //} else if (gz> 9000 & gz <= 35000) // {printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.25-1005); //} else if (gz> 35000 & gz <= 55000) // {printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.30-2755); //} else if (gz> 55000 & gz <= 80000) // {printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.35-5505); //} else if (gz> 80000 )// {Printf ("your personal tax is: %. 2f \ n ", grs = gz * 0.45-13505); //} else {// printf (" no money \ n "); ///} //} else {// printf ("You're ugly !! \ N "); // Question 8 // double jine, jiangjin; // printf (" Enter your amount (RMB) \ n "); // scanf ("% lf", & jine); // if (jine> 0) {// if (jine <= 10) {// printf ("Your reward is: %. 4f RMB \ n ", jiangjin = jine * 0.1); //} else if (jine> 10 & jine <= 20) // {printf ("Your reward is: %. 4f million \ n ", jiangjin = 10*0.1 + (jine-10) * 0.075); //} else if (jine> 20 & jine <= 40) // {printf ("Your reward is: %. 4f million \ n ", jiangjin = 10*0.1 + 10*0.075 + (jine-20) * 0.05); //} else if (jine> 40 & jine <= 60) // {printf ("Your reward is: %. 4f Yuan \ n ", jiangjin = 10*0.1 + 10*0.075 + 20*0.05 + (jine-40) * 0.03 ); //} else if (jine> 60 & jine <= 100) // {printf ("Your reward is: %. 4f Yuan \ n ", jiangjin = 10*0.1 + 10*0.075 + 20*0.05 + 20*0.03 + (jine-60) * 0.15 ); //} else if (jine> 100) // {printf ("Your reward is: %. 4f Yuan \ n ", jiangjin = 10*0.1 + 10*0.075 + 20*0.05 + 20*0.03 + 40*0.015 + (jine-100 )); //} // else {// printf ("You are amazing "); /// //} // else {// printf ("I am really tired "); ///} //// company employee // int jy, xl, js, sum; // printf ("Enter your work experience \ n "); // scanf ("% d", & jy); // printf ("Enter your degree \ n"); // scanf ("% d", & xl ); // printf ("enter technical qualifications \ n"); // scanf ("% d", & js); // if (jy = 0) {// printf ("fresh graduates 0 points \ n"); //} else if (jy <= 1) // {printf ("less than one year of work experience: 1 point \ n"); //} else if (jy> 1 & jy <3) // {printf ("2 points \ n"); //} else if (jy> = 3 & jy <7) // {printf ("3 points \ n"); //} else if (jy> = 7) // {printf ("4 points \ n "); ///} // else {// printf ("your input is incorrect \ n"); // switch (xl) {// case 1: // printf ("1 point \ n"); // break; // case 2: // printf ("2 points \ n"); // break; // case 3: // printf ("graduate student + 3 points \ n"); // break; // default: printf ("your input work experience is incorrect \ n"); // break; //} // switch (js) {// case 0: // printf ("unqualified 0 points \ n"); // break; // case 1: // printf ("Beginner 1 point \ n"); // break; // case 2: // printf ("Intermediate 2 points \ n"); // break; // case 3: // printf ("advanced 3 points \ n "); // break; // default: // printf ("your input qualifications are incorrect \ n"); // break; ///} // printf ("top salary: % d \ n", sum = jy + xl + js ); ///// bank deposit // double m; //// char hq; // int dq; // printf ("Enter your deposit amount \ n"); // scanf ("% lf", & m ); // printf ("Enter your deposit type, please press d (regular) or h (current) \ n"); // scanf ("% c", & hq ); //// if (hq = 'H' | hq = 'H') {// printf ("Your money is: %. 6f \ n ", m * 0.0035); // else if (hq = 'D' | hq = 'D ') /// {/// printf ("Enter your choice (1-> full storage, 2-> zero storage, 3-> set the active ratio \ n "); // scanf ("% d", & dq); // switch (dq) {// case 1: // printf ("the total fee is %. 6f \ n ", m * 0.0325); // break; // case 2: // printf (" the sum of 0 s is %. 6f \ n ", m * 0.0285); // break; // case 3: // printf (" the sum of money is %. 6f \ n ", m x 0.0325*0.6); // break; // default: // break; //} // else {// printf ("your input is incorrect "); ///} // seldom go to the park // int m = 120, zl; // float sg; // printf ("select a type (1-> old man, 2-student, 3-officer, 4-child) \ n "); // scanf (" % d ", & zl ); // if (zl = 1) // {// printf ("required amount: % d \ n", m * 0 ); //} // else if (zl = 2 | zl = 3) // {// printf ("required amount: % d \ n ", m/2); //} else if (zl = 4) // {// printf ("Enter the height of the ticket (meter) \ n "); // scanf ("% f", & sg); // if (sg <1.20) // {// printf ("no ticket purchased \ n "); //} else if (sg> = 1.20) & (sg <= 1.50) // {// printf ("buy children's ticket %. f $ \ n ", m * 0.3); // else {// printf (" buy adult ticket \ n "); ///} //} else // {// printf ("your input is incorrect \ n ");////}//

 

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.