Introduction to the C + + algorithm race Classic Page16 exercise 1-2 temperature

Source: Internet
Author: User

Title: Input Fahrenheit temperature F, output corresponding to C, 3 decimal places reserved.

Tip: C=5 (f-32)/9

(1) Declaring floating-point type variable f,c, respectively, representing the input Fahrenheit temperature and the output Celsius temperature

double F; //  double C; // Celsius temperature of the output

(2) input Fahrenheit temperature F:

scanf ("%lf", &f);

(3) Assign the variable C according to the conversion formula of c=5 (F-32)/9:

C= (double) (5* (f-a)/9);

(4) Output Celsius temperature c:

printf ("%.3lf", c);

Full code:

//P16 Exercise 1-2 temperature#include <cstdio>DoubleF//temperature of the input FahrenheitDoubleC//Celsius temperature of the outputintMain () {scanf ("%LF",&G); C=(Double)(5* (f +)/9);//c=5 (f-32)/9printf ("%.3LF", c); return 0; } 

Introduction to the C + + algorithm race Classic Page16 exercise 1-2 temperature

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.