Practice 1-5 Modify the temperature conversion program to print a temperature conversion table in reverse order (i.e., from 300 degrees to 0 degrees).
The code is as follows:
#include <stdio.h>//contains information about the standard library. intMain ()//defines a function named Main, which does not accept parameter values. { floatFahr;//degrees Fahrenheit. floatCelsius//Celsius. intlower, upper, step; Lower=0;//the lower limit of the temperature gauge. Upper = -;//the upper limit of the temperature gauge. Step = -;//step. //Print the title at the top. printf"%3s%6s\n","C","F"); //start the conversion from the upper limit of the temperature gauge. for(Celsius = upper; Celsius >=0; Celsius = Celsius-Step) { //conversion algorithm, degree Celsius specifically for Fahrenheit. Fahr = (9.0/5.0) * Celsius +32.0; //the degree of Celsius display occupies at least 3 characters justifies, and the decimal part is omitted;//the Fahrenheit display occupies at least 6 characters justifies, and takes a decimal place;printf"%3.0f%6.1f\n", Celsius, Fahr); } getch (); //prevent the console from flashing through, you need to accept any characters after you close the console. return 0;//returns a shape to the execution environment, and 0 represents a successful execution. }
Personal Understanding:
The purpose of the exercise is to master the use of the For loop.
In the actual programming process, you can choose the while and for any one of the loop statements, mainly depends on which kind of gengqing hi.
The For statement is more suitable for initializing and increasing the step size as a single statement and logically related scenario, because it puts the loop control statements together and is more compact than the Hile statement.
C Programming language Exercises 1-5