Tan Haoqiang C language exercises and detailed answers

Reference herein Hey passenger network Java combat

Preface

This article is about C language programming (Tan Haoqiang C language third edition) after-class exercises and answers. After learning C language programming, do a few related exercises to review the knowledge points. In the process, the knowledge points that are very abstract and obscure may be combined with a case question, and there may be unexpected results!
 

table of Contents

third chapter

  • Tan Haoqiang C Language Third Edition, Question 3.7, page 67

Chapter Four

  • Tan Haoqiang C Language Third Edition Question 4.4, Page 88
  • Tan Haoqiang C Language Third Edition Page 89 Question 4.8
  • Tan Haoqiang C Language Third Edition, Question 4.9, Page 89
  • Tan Haoqiang, C language, third edition, page 90, question 4.10

chapter Five

  • Tan Haoqiang C Language Third Edition, Page 111, Question 5.4
  • Tan Haoqiang C Language Third Edition, Question 5.5, Page 111
  • Tan Haoqiang C Language Third Edition, Page 111, Question 5.6
  • Tan Haoqiang C Language Third Edition Page 112, Question 5.7
  • Tan Haoqiang C Language Third Edition Page 111, Question 5.8
  • Tan Haoqiang C Language Third Edition Page 111, Question 5.9
  • Tan Haoqiang, C language, third edition, page 111, question 5.10

To be continued. . . . .

 

Text: C language programming exercises and answers

third chapter

3.7

Description : To translate "China" into a password, the password rule is: replace the original letter with the fourth letter after the original letter. (Tan Haoqiang C Language Third Edition, Question 3.7, page 67)

Topic : To translate "China" into a password, the password rule is: replace the original letter with the fourth letter after the original letter. For example, if the fourth letter after the letter "A" is "E", replace "A" with "E". Therefore, "China" should be translated as "Glmre". Please make a program to make the values ​​of the five variables c1, c2,, c3, c4, and c5 be'C','h','i','n','a', After calculation, make c1, c2, c3, c4, and c5 become'G','l','m','r','e' respectively, and output.

Answer : https://haicoder.net/case/thq-c/c-3-7.html

 

Chapter Four

4.4

Description : Given a number of characters , and printed out at the appropriate format. (Tan Haoqiang C Language Third Edition, Question 4.4, page 88)

Question : If a = 3, b = 4, c = 5, x = 1.2, y = 2.4, z = -3.6, u = 51274, n = 128765, c1 ='a', c 2 ='b'. The following output formats and want results, write program (including the definition of a variable type and design output). The required output results are as follows:

a= 3  b= 3  c= 5

x=1.200000,y=2.400000,z=-3.600000

x+y= 3.60  y+z=-1.20  z+x=-2.40

u= 51274  n=   128765

c1=‘a’ or 97(ASCII)

c2='b' or 98(ASCII)

Answer : https://haicoder.net/case/thq-c/c-4-4.html

4.8

Description : The user is required to input the radius and height of the cylinder to find the relevant information about the circumference, area, surface area, volume of the cylinder, and volume of the cylinder. (Tan Haoqiang C language third edition, page 89, question 4.8)

Question : Set the radius of the circle r = 1.5 and the height of the cylinder h = 3. Find the circumference, area of ​​the circle, surface area of ​​the sphere, volume of the sphere, and volume of the cylinder. Use scanf to input data and output calculation results. When outputting, a text description is required, taking 2 digits after the decimal point. Please write a program.

Answer : https://haicoder.net/case/thq-c/c-4-8.html

4.9

Description : Given a scene and a calculation formula, convert the input Fahrenheit temperature into Celsius according to the formula. (Tan Haoqiang C Language Third Edition, Question 4.9, page 89)

Topic: Enter a temperature in Fahrenheit, and output a temperature in Celsius. The formula is: c = 5/9 (F-32). The output must have a text description and take 2 decimal places.

Answer : https://haicoder.net/case/thq-c/c-4-9.html

4.10

Description : Verify putchar function and printf difference function as well as C language in each of the type difference between the field, it is not regarded as the same data. (Tan Haoqiang C language third edition, page 90, question 4.10)

Title : programmed, with getchar function reads two characters to c1, c2, and then outputs the two characters and with the putchar function printf function. Consider the following questions:

(1) variable c1, c2 should be defined as a character or integer ? Or both?

(2) What should I do if the ASCII code of c1 and c2 is required to be output ? Use putchar function or printf function?

(3) Can integer variables and character variables replace each other under any circumstances? Such as: char c1, c2; and int c1, c2; are they unconditionally equivalent?

Answer: https://haicoder.net/case/thq-c/c-4-10.html

 

chapter Five

5.4

Description : Take the maximum value, enter three values ​​randomly in the keyboard, and print out the maximum value. (Tan Haoqiang C language third edition, page 111, question 5.4)

Title : there are three integers a, b, c, a keyboard input, wherein the maximum number of outputs.

Answer : https://haicoder.net/case/thq-c/c-5-4.html

5.5

Description : Given a specified function , is programmed according to a given function. (Tan Haoqiang C language third edition, page 111, question 5.5)

Subject: There is a function:
www.haicoder.net

Write a program, input x and output y value.

Answer: https://haicoder.net/case/thq-c/c-5-5.html

5.6

Description : Convert students' specific grades into corresponding grades. (Tan Haoqiang C language third edition, page 111, question 5.6)

Topic : Given a 100-point system score, the output grades are required to be'A','B','C','D', and'E'. 90 points or more is considered as'A', 80 to 89 points as'B', 70 to 79 as'C', 60 to 69 as'D', and 60 points or less as'E'.

Answer : https://haicoder.net/case/thq-c/c-5-6.html

5.7

Description : Enter a number with no more than 5 digits, and output the relevant attributes of this number as required. (Tan Haoqiang C language third edition, page 112, question 5.7)

Topic : Give a positive integer of no more than 5 digits, request:

  1. Find out how many digits it is;
  2. Output each digit separately;
  3. Output the digits in reverse order, for example, if the original number is 321, 123 should be output.

Answer : https://haicoder.net/case/thq-c/c-5-7.html

5.8

Description : According to a scene, different data values ​​get different data. Situational topic. (Tan Haoqiang C language third edition, page 112, question 5.8)

Topic : Bonuses issued by companies are based on profit commissions. If the profit I is less than or equal to 100,000 yuan, the bonus can be increased by 10%; when the profit is higher than 100,000 yuan and less than 200,000 yuan (100 000 <I <= 200 000), the part below 100,000 yuan shall be 10%. % Commission, the part higher than 100 000 yuan can be commissioned 7.5%; when 200 000 <I <= 400 000, the part lower than 200 000 yuan will still be commissioned according to the above method (the same below). The part higher than 200 000 yuan is 5% commission; when 400 000 <I <= 600 000 yuan, the part higher than 400 000 yuan is 3% commission; when 600 000 <I <= 1000 000, more than 600 000 yuan 1.5% commission for the part; when I>1000 000, the part exceeding 1000 000 yuan is commissioned at 1%. Enter the profit I of the current month from the keyboard to find the total amount of bonuses to be issued.

Requirements :

  1. Use if statements to program;
  2. Use switch statements to program.

Answer : https://haicoder.net/case/thq-c/c-5-8.html

5.9

Description : Enter some numbers and sort these numbers from smallest to largest. (Tan Haoqiang C language third edition, page 112, question 5.9)

Title : four input integer , the required output in ascending order.

Answer : https://haicoder.net/case/thq-c/c-5-9.html

5.10

Description : There is a number axis, and there is a circle in each of the four areas of the number axis. If a point is in the circle area, it means it has a value, if it is not in the circle area, there is no value. (Tan Haoqiang C language third edition, page 112, question 5.10)

Topic : There are 4 circular towers, the center of the circle is (2, 2), (-2, 2), (-2, -2), (2, -2), the radius of the circle is 1, see the figure below. The height of these 4 towers is 10, and there is no building outside the tower. Enter the coordinates of any point now and find the height of the building at that point (the height outside the tower is zero).

www.haicoder.net

Answer : https://haicoder.net/case/thq-c/c-5-10.html

 

Follow-up

However, because the number of articles is too large, it is not easy to organize, so if the update is too slow, please forgive me, I will update the article as fast as I can, you can pay attention to me first, or bookmark this article, I will continue to update, the above case is available to a certain C language-based students to see, some do question if you feel pressure, can go to all kinds of network learning C language tutorial, I am here, of course the most important source of top exercises and answers Hi customer network .

To read more articles, you can follow the public account below:
Haicoder (www.haicoder.net)

Guess you like

Origin blog.csdn.net/weixin_41384860/article/details/108123401