摂氏を華氏に変換する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 = (fahrenheit - 32) / 1.8



Hope this helps!

Source link

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です