使用 C 語言程式將華氏溫度轉換為攝氏溫度


我們實現將華氏溫度轉換為攝氏溫度的邏輯如下所示 −

celsius = (fahrenheit - 32)*5/9;

演算法

參考下面給出的演算法將華氏溫度轉換為攝氏溫度。

Step 1: Declare two variables farh, cels
Step 2: Enter Fahrenheit value at run time
Step 3: Apply formula to convert
        Cels=(farh-32)*5/9;
Step 4: Print cels

舉例

下面是將華氏溫度轉換為攝氏溫度的 C 語言程式 −

#include<stdio.h>
int main(){
   float fahrenheit, celsius;
   //get the limit of fibonacci series
   printf("Enter Fahrenheit: 
");    scanf("%f",&fahrenheit);    celsius = (fahrenheit - 32)*5/9;    printf("Celsius: %f
", celsius);    return 0; }

輸出

執行上述程式後,將產生以下結果 −

Enter Fahrenheit:

100
Celsius: 37.777779

更新時間: 2023-11-04

48K+ 瀏覽量

啟動您的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.