answersLogoWhite

0


Best Answer
Code Example:/********************************************************************************* MODULE: main.c******************************************************************************** DESCRIPTION:* Program that takes a temperature from the user on the command line, then* displays that temperature as celsius converted to Fahrenheit, and* as Fahrenheit converted to celsius.********************************************************************************/#include #define iARGS_REQUIRED 2#define iARG_EXE 0#define iARG_INPUT 1static floatfCelsiusToFahrenheit( float fCelsius );static floatfFahrenheitToCelsius( float fFahrenheit );/********************************************************************************* MAIN********************************************************************************/intmain( int iArgc, char *acpArgv[] ){ float fFahrenheit = 0.0; float fCelsius = 0.0; float fInput = 0.0; /* user didn't provide a temperature on the command line */ if(iArgc != iARGS_REQUIRED) { fprintf(stderr, "Usage: %s [temperature]\n", acpArgv[iARG_EXE]); return 0; } /* read the given temperature into the fInput variable */ sscanf(acpArgv[iARG_INPUT], "%f", &fInput); /* fInput treated as celsius and converted to Fahrenheit */ fFahrenheit = fCelsiusToFahrenheit(fInput); /* fInput treated as Fahrenheit and converted to celsius */ fCelsius = fFahrenheitToCelsius(fInput); printf( "%.2f degrees Fahrenheit is %.2f degrees celsius.\n", fInput, fCelsius ); printf( "%.2f degrees celsius is %.2f degrees Fahrenheit.\n", fInput, fFahrenheit ); return 0;}/********************************************************************************* STATIC FUNCTION: fCelsiusToFahrenheit******************************************************************************** DESCRIPTION:* Converts a celsius temperature to Fahrenheit.** PARAMETERS:* fCelsius: The temperature in celsius to convert.** RETURNS:* fCelsius converted to Fahrenheit.********************************************************************************/static floatfCelsiusToFahrenheit( float fCelsius ){ return (fCelsius * 1.8) + 32;}/********************************************************************************* STATIC FUNCTION: fFahrenheitToCelsius******************************************************************************** DESCRIPTION:* Converts a Fahrenheit temperature to celsius.** PARAMETERS:* fFahrenheit: The temperature in Fahrenheit to convert.** RETURNS:* fFahrenheit converted to celsius.********************************************************************************/static floatfFahrenheitToCelsius( float fFahrenheit ){ return (fFahrenheit - 32) / 1.8;}
User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

Use the following functions:

double celsius2fahrenheit (double celsius) {

return celsius * 9 / 5 + 32;

}

double fahrenheit2celsius (double fahrenheit) {

return (fahrenheit - 32) * 5 / 9;

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include <iostream>

using namespace std;

int main()

{

double x;

cout << "Enter temperature in celcius: ";

cin >> x;

cout << x * 9 / 5 + 32 << endl;

char wait;

cin >> wait;

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

The following functions will provide all the conversions you need.

double celsius_to_fahrenheit (double c) {

return c * 9 / 5 + 32;

}

double fahrenheit_to_celsius (double f) {

return (f - 32) / 9 * 5;

}

double celsius_to_kelvin (double c) {

return c + 273.15;

}

double kelvin_to_celsius (double k) {

return k - 273.15;

}

double fahrenheit_to_kelvin (double f) {

return celsius_to_kelvin (fahrenheit_to_celsius (f));

}

double kelvin_to_fahrenheit (double k) {

return celsius_to_fahrenheit (kelvin_to_celsius (k));

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The conversion from Celsius to Fahrenheit in assembly language is not different from the same conversion in any other programming language; all implement the same formula F = 32 + C * 9/5, where F is the temperature in Fahrenheit and C is the same temperature in Celsius.

Details of the implementation in a specific assembly language are of course subject to the definition of that particular assembly language.

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

To convert temperature from Fahrenheit to Celsius we use a simple function that accepts a temperature in Fahrenheit and returns the equivalent temperature in Celsius. To achieve this we need to know the formula to convert from Fahrenheit to Celsius. This can easily be calculated by comparing 0 degrees Celsius and 100 degrees Celsius to the equivalent temperatures in Fahrenheit:

0 degrees Celsius = 32 degrees Fahrenheit

100 degrees Celsius = 212 degrees Fahrenheit

From the first temperature we can see that the two scales are offset by exactly 32 degrees, so we must subtract 32 degrees from the Fahrenheit temperature in order to align both scales with zero.

0 degrees Celsius = 0 + 32 degrees Fahrenheit 100 degrees Celsius = 180 + 32 degrees Fahrenheit

Having aligned the two scales, we can now see that a difference of 100 degrees Celsius is exactly equivalent to a difference of 180 degrees Fahrenheit. Combining the offset (32) with the ratio (100/180), we obtain the following conversion formulas, where C is the temperature in degrees Celsius and F is the temperature in degrees Fahrenheit:

C = (F-32)*(100/180) = (F-32)*(5/9) = (F-32)*0.55555...

or

C = (F-32) / (180/100) = (F-32)/(9/5) = (F-32)/1.8

Note that we must use parenthesis to ensure the correct order of evaluation (division normally has a higher precedence than subtraction).

These formulas are exactly equivalent, so it is merely a matter of taste which you prefer in code:

double fahrenheit_to_celsius (double f) { return (f-32)*5/9; }

or

double fahrenheit_to_celsius (double f) { return (f-32)/1.8; }

Note that we cannot express 0.55555... explicitly in code (it would be non-portable) so we must use 5/9 to gain maximum precision across all implementations. However, 5/9 is a constant expression and therefore a compile-time operation, so there is no runtime cost.

Usage:

double c1 = fahrenheit_to_celsius (32.0); // c1 = 0.0 (freezing point of water)

double c2 = fahrenheit_to_celsius (212.0); // c2 = 100.0 (boiling point of water)

double c3 = fahrenheit_to_celsius (-40.0); // c3 = -40.0 (parity)

double c4 = fahrenheit_to_celsius (-459.67); // c4 = -273.150 (absolute zero: 0 degrees Kelvin)

Now that we know how the formula and function for Fahrenheit to Celsius conversion was constructed, the complementary function should be self-explanatory:

double celsius_to_fahrenheit (double c) { return c*9/5+32; }

or

double celsius_to_fahrenheit (double c) { return c*1.8+32; }

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Temperature in Fahrenheit is equal to (9/5 x Temperature in Celsius) + 32

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program in C to convert temperatures between Fahrenheit and Celsius?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

To convert Celsius temperatures to Fahrenheit temperatures quickly without?

Formula: Fahrenheit = (Celsius x 1.8) + 32


Why is it fifty degrees hotter on a Celsius scale?

That's wrong. That's not how you convert temperatures between Celsius and Fahrenheit.


How do you convert 50c to Fahrenheit?

To convert Celsius temperatures into Fahrenheit:Begin by multiplying the Celsius temperature by 9.Divide the answer by 5.Now add 32.122 Degrees Fahrenheit.


How do you convert degree celsius to degree feranith?

To convert temperatures in degrees Celsius to Fahrenheit, multiply by 1.8 (or 9/5) and add 32.


If it is 76 F what will it be in Celsius?

76 degree Fahrenheit is 24.44 Celsius. You do the Math: To convert Fahrenheit temperatures into Celsius: Begin by subtracting 32 from the Fahrenheit number. Divide the answer by 9. Then multiply that answer by 5.


WHICH IS FALSE 5 degrees celsius is warmer than 5 degrees Fahrenheit 15 degrees CELSIUS IS COOLER THAN 60 DEGREES FAHRENHEIT 30 DEGREES CELSIUS IS WARMER THAN 90 DEGREES FAHRENHEIT 35 DEGREES CELSIUS?

I suggest you convert each of the Fahrenheit temperatures to Celsius (or the other way round, each of the Celsius temperatures to Fahrenheit), and then compare.


How can you convert temperature in degrees Fahrenheit to degrees Celsius?

How to convert Fahrenheit temperatures to CelsiusSubtract 32o to adjust for the offset in the Fahrenheit scale.Multiply the result by 5/9.Example: convert 98.6o Fahrenheit to Celsius.98.6 - 32 = 66.666.6 * 5/9 = 333/9 = 37o C.


How do you convert between Fahrenheit and minus Celsius temperature?

To convert from celsius to fahrenheit use the following formula : F = (C * 9/5) + 32


How to Convert 62.5 degrees Fahrenheit to Celsius?

Formula for conversion between Fahrenheit and Celsius is: Fahrenheit=5/9*Celsius+32 Celsius =(Farenheit-32)*9/5


Which temperature is colder 40f or 10c?

40 degrees fahrenheit is about 4.4 degrees celsius, while 10 celsius is 50 degrees fahrenheit so 40 fahrenheit is the colder temperature. The formulas to convert between celsius and fahrenheit temperatures (where F is the Fahrenheit temperature and C is the Celsius temperature in degrees) are as follows: Celsius to Fahrenheit: F = C &times; 9/5 + 32 Fahrenheit to Celsius: C = (F &minus; 32) x 5/9


What is the formula for converting temperatures?

Convert Fahrenheit to Celsius: Celsius = (5/9) * (Fahrenheit - 32)Convert Celsius to Fahrenheit: Fahrenheit = (9/5) * Celsius + 32Convert Celsius to kelvin: Kelvin = Celsius + 273.15Convert kelvin to Celsius: Celsius = kelvin - 273.15


What is the conversion formula to convert temperatures from Celsius into Fahrenheit degrees?

[&deg;F] = [&deg;C] &times; 9/5 + 32