C Programming language Exercises 1-5

Source: Internet
Author: User

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

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.