160809212 Tian Jing Cheng C language Programming Experiment 2 selection structure Programming _ Advanced

Source: Internet
Author: User
Tags clear screen

Experiment 2-6 guess the number game experiment requires:

Write a C program to implement a guessing number game within [1-100] .

(1) The system randomly generates a random number between [1-100] .

(2) Enter any number. The number requirement is a natural number of 1-100.

(3) The system determines the number you enter. If the number entered by the player is compared with the number of randomly generated computers, the number entered is smaller than the randomly generated number, the system will prompt you, the number is too small please re-enter . If the number entered by the player is compared to the number of randomly generated computers, if the number entered is larger than the number generated randomly, you will be prompted, the number is too large please re-enter . If the character entered by the player is not a valid character, you will be prompted that the number you entered is not valid, please re-enter it. If the two numbers are the same, the output " Congratulations, guess right!" ".

(4) Every guess once, the system will be recorded, the game is over, showing how many times the total speculation .

(5) After the game, according to the number of guesses, give comments (3 times inside guess, genius!) ,4-7 guesses, intelligence normal,8 times above guessed, stupid ).

(6) can be completed under the basic framework of the following procedures, such as the need for additional variables to increase their own source code

Reference:

#include <stdio.h>

#include <stdlib.h>

Guess number Game

int main ()

{

int mynumber,yournumber,count=0;

Char c;

do{

Specify the current time for the seed value

Srand ((unsigned) time (NULL));

Generate [1,100] The random number of this room

MyNumber = (rand ()% (101-1)) + 1;

do{

printf ("Please enter the value you suspect:");

scanf ("%d", &yournumber);

// Please enter the code here, guess the number, and give a hint, and record the number of times

              // ...

}while (yournumber!=mynumber);

printf ("You have guessed%d times \ n",count);

// Please enter the code here, according to the number of user guesses to give the evaluation

// ...

printf ("Continue to press y/y, exit please press n/n:");

GetChar ();

C=getchar ();

System ("CLS"); Clear Screen function

}while (c== ' y ' | | c== ' y ');

return 0;

}

Source:

#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intMynumber,yournumber,count=0; CharC;  Do{srand (unsigned) time (NULL)); MyNumber= (rand ()% (101-1)) +1;  Do{printf ("Please enter the value you suspect:"); scanf ("%d",&yournumber); Count++; if(yournumber>mynumber) printf ("The number is too large please re-enter \ n"); Else if(yournumber<mynumber) printf ("The number is too small please re-enter \ n"); Else if(yournumber!=mynumber) printf ("the number you entered is not valid, please re-enter \ n"); }             while(yournumber!=MyNumber); {            if(count<=3) printf ("Genius! \ n"); Else if(count>3&& count<=7) printf ("Intelligence is normal! \ n"); Elseprintf ("Stupid! "); } printf ("you've guessed%d times \ n", Count); printf ("Press y/y to continue, please press n/n:\n to exit.");        GetChar (); C=GetChar (); System ("CLS"); } while(c=='Y'|| c=='y'); return 0;}

Experiment 2-7 to determine whether to become a triangular experiment requires:

(1) Enter the three sides of the triangle, determine whether the triangle can be formed, the output can become a triangle.

(2) If it is a triangle, calculate the circumference and area, and output.

Source:
#include <stdio.h>#include<math.h>intMain () {intA=0, b=0, c=0, Z; floatS,ave; printf ("Please enter three edges: \ n"); scanf ("%d%d%d",&a,&b,&c); if(A+b>=c && a+c>=b && b+c>=a) {s= (a+b+c) *1/2.0; Ave=sqrt (s* (s-a) * (s-b) * (S-c)); printf ("Area:%f\n", Ave); Z=a+b+C; printf ("perimeter is:%d\n", z); }     Elseprintf ("cannot form a triangle. \ n"); return 0;}

Experiment 2-8 Personal Income Tax Calculator experiment requirements:

Write a selection structure program, enter the total monthly income of the individual, calculate his tax payable this month and after-tax income (the calculation method is attached: personal tax rate table).

(1) complete with if statement and switch statement respectively;

(2) can be completed under the basic framework of the following procedures, such as the need for additional variables to increase their own source code:

#include <stdio.h>

int main ()

{

float salary,tax=0,aftertaxincome=0;

printf ("Please enter your total revenue for this month (yuan):");

scanf ("%f", &salary);

// The following solution should be paid to the individual and tax and after-tax income aftertaxincome

printf ("You should pay personal and tax%.2f yuan this month, after-tax income is%.2f yuan.") \ n ", tax, aftertaxincome);

return 0;

}

Attached: personal tax rate table

Adjusted for the September 1, 2011, the 7-level excess progressive personal income tax rate, which was introduced in 2012

Taxable personal Income tax = Taxable Income amount x applicable tax rate - Calculator Deduction Number

Deduction standard 3500 yuan/month (formally implemented from September 1, 2011 onwards) (Salary, salary income applies)

Tax exemption Amount 3500 yuan (applicable to salary and salary income)

Series

All-month taxable income (incl. tax level) "Tax Information Network"

All-month taxable income (excl. Tax level)

Tax rate (%)

Calculator Deduction Number

1

No more than 1,500 yuan

No more than 1455 dollars.

3

0

2

More than $1,500 to $4,500

More than $1455 to $4155

10

105

3

More than $4,500 to $9,000

More than $4155 to $7755

20

555

4

More than $9,000 to $35,000

More than $7755 to $27255

25

1,005

5

More than $35,000 to $55,000

More than $27255 to $41255

30

2,755

6

More than $55,000 to $80,000

More than $41255 to $57505

35

5,505

7

More than 80,000 yuan of parts

More than 57505 yuan of parts

45

13,505

Note:

For example: One month salary minus social security individual payment amount and Housing Provident Fund individual payment amount of 5500 yuan, a tax calculation:(5500-3500) *10%-105= 95 yuan

Source code (using the IF statement to complete):
#include <stdio.h>  int main ()  {      float salary,tax=0,aftertaxincome=0,i;       printf ("Please enter your total revenue for this month (yuan):");      scanf ("%f", &salary);    i=salary-3500;  {    if (i<=0)    tax=0;   else if (i<=1500)   tax=i*0.03;   else if (i>1500 && i<=4500)   tax=i*0.1-105;   else if (i>4500 && i<=9000)   tax=i*0.2-555;   else if (i>9000 && i<=35000)   tax=i*0.25-1005;  }   Aftertaxincome=salary-tax;   printf ("You should pay personal and tax%.2f yuan this month, after-tax income is%.2f yuan.") \ n ", tax, aftertaxincome);      return 0;  }   

  

Experiment Experience

This homework is very difficult, do it very hard, the first problem on the card for a long time, again and again the screening, debugging place, now my problem is a function can, a number of functions put together on the problem, there are floating-point numbers and integers are sometimes attention is not accurate, system ("CLS"); This seems Baidu or something still do not understand.

The last question still has some questions, need to study, for the time being, if can solve, will pay.

160809212 Tian Jing Cheng C language Programming Experiment 2 selection structure Programming _ Advanced

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.