K&R C Exercise 1-15: Rewrite Temperature Conversion Using a Function

Exercise 1-15. Rewrite the temperature conversion program of Section 1.2 to use a function. Section 1.2 of K&R embeds the conversion formula directly inside main. It works — but it ties the formula to one spot in the code. This exercise asks you to extract that logic into a separate function called celsius. The payoff …

K\&R C Exercise 1-5: Reverse Temperature Table (300 to 0)

Exercise 1-5. Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0. Approach The original K&R temperature program counts up: it starts fahr at 0, adds the step each iteration, and stops when fahr > 300. Reversing the table means changing exactly three things: (1) start …

K&R C Exercise 1-3: Add a Heading to the Temperature Table

Exercise 1-3. Modify the temperature conversion program to print a heading above the table. What the Base Program Does K&R Section 1.2 introduces a program that prints a Fahrenheit-to-Celsius conversion table from 0 to 300 in steps of 20. It uses integer arithmetic — celsius = 5 * (fahr – 32) / 9 — and …

K&R C Exercise 1-4: Celsius to Fahrenheit Table

Exercise 1-4. Write a program to print the corresponding Celsius to Fahrenheit table. Approach K&R Chapter 1 opens with a Fahrenheit-to-Celsius table, converting F values to Celsius using C = 5 × (F − 32) / 9. This exercise asks for the inverse: step through Celsius values (0, 20, 40, …, 300) and compute the …