JavaScript 程序:摄氏度转换为华氏度

要理解此示例,您应了解以下 JavaScript 编程 主题


您可以使用以下公式将摄氏度转换为华氏度

fahrenheit = celsius * 1.8 + 32

示例:摄氏度转华氏度

// program to convert celsius to fahrenheit
// ask the celsius value to the user 
const celsius = prompt("Enter a celsius value: ");

// calculate fahrenheit
const fahrenheit = (celsius * 1.8) + 32

// display the result
console.log(`${celsius} degree celsius is equal to ${fahrenheit} degree fahrenheit.`);

输出

Enter a celsius value: 55
55 degree celsius is equal to 131 degree fahrenheit.

在上面的程序中,用户输入的摄氏度值存储在 celsius 变量中。然后使用华氏度公式将摄氏度转换为华氏度。


您可以使用以下公式将华氏度转换为摄氏度

celsius = (fahrenheit - 32) / 1.8

另请阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战