C Primer Plus 第十章第十題

10. Write a program that declare a 3×5 array and initializes it to some values of your choice. Have the program print the values, double all the values, and then display the new values. Write a function to the displaying and a second function to do the doubling. Have the function take the array name and the number of rows as arguments.

C Primer Plus 第十章第六題

6. Write a program that initialize a two-dimensional arrray of double and uses one of the copy functions from exercise 2 to copy it to a second two-dimensional array. (Because a two-dimensional array is an array of arrays, a one dimensional copy function can be used with each subarray.)

C Primer Plus 第九章第二題

2. Devise a function chiline(ch,i,j) that prints the requested character in columns i through j. Test it in a simple driver.

C Primer Plus 第八章第八題

8. Write a program that shows you a menu offering you the choice of addition, subtraction, multiplication, or division. After getting your choice, the program asks for two numbers then performs the requested operation. The program should accept only the offered menu choice. It should use type float for the numbers and allow the user to try again if he or she fails to enter a number. In the case of subtraction, the program should prompt the user to enter a new value if 0 is entered as the value for second number. A typical program run should look like this.
Enter the operation of your choice:
a. add s. subtract
m. multiply d. divide
q. quit
Enter first number: 22.4
Enter second number: one
one is not an number.
Please enter a number, such as 2.5, -1.78E8, or 3: 1
22.4 + 1= 23.4
Enter the operation of your choice:
a. add s. subtract
m. multiply d. divide
q. quit
Enter first number: 18.4
Enter second number: 0
Enter a number other than 0: 0.2
18.4 / 0.2 = 92
Enter the operation of your choice
a. add s. subtract
m. multiply d. divide
q. quit

C Primer Plus 第七章第八題

8. Modify assumption a. in exercise 7 so that the program presents a menu of pay rates from which to choose. Use a switch to select the pay rate. The beginning of a run should look something like this:

Enter the number corresponding to the desires pay rate or action:
1) $8.75 /hr 2) $9.323/hr
3) $10.00/hr 4) $11.20/hr
5) quit

If choices 1 through 4 are selected, the program should request the hours worked. The program should recycle until 5 is entered. If something other than choices are and then recycle. Use #defined constants for the carious earning rates and tax rates.

C Primer Plus 第七章第七題

7. Write a program that requests the hours worked in a week and then prints the gross pay, the taxes, and the net pay. Assume the following:
a. Basic pay rate = $10.00/hr
b. Overtime (in excess of 40 hours) = time and a half
c. Tax rate 15% of the first $300
20% of the next $150
25% of the rest
Use #define constants, and don’t worry if the example does not conform to current tax law.

C Primer Plus 第七章第九題

9. Write a program that accepts an integer as input and then displays all the prime numbers smaller than or equal to that number.

C Primer Plus 第六章第十二題

12. Write a program that creates two eight-element arrays of double and uses a loop to let the user enter values for eight elements of the first array. Have the program set the elements of the second array to the cumulative totals of the elements of the first array. For example, the fourth element of the second array should equal the sum of the first four elements of the first array, and the fifth element of the second array should equal the sum of the first five elements of the first array. Finally, use a loop to display the contents of the two arrays, with the first array displayed on one line and with each element of the second array displayed below the corresponding element of the first array.

C Primer Plus 第六章第四題

4. Have a program request the user enter an uppercase letter. Use nested loops to produce a pyramid pattern like this:


The pattern should extend to the character entered. For example, the preceding pattern would result from a input value of E. Hint: Use an outer loop to handle the rows. Use three inner loops in a row, one to handle the spaces, one for printing letters in ascending order, and one for printing letters in descending order.

C Primer Plus 第四章第五題

5. Write a program that request the user’s first name and then the user’s last name. Have it print the entered names on one line and the number of letters in each name on the following line. align each letter count with the end of the correspomding name, as in the following:

   Melissa Honeybee
         7        8

Next have it print the same information, but with the count aligned with the beginning of each name.

   Melissa Honeybee
   7       8