ตรรกะที่เราใช้ในการแปลงฟาเรนไฮต์เป็นเซลเซียสมีดังนี้ −
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: \n");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f \n", celsius);
return 0;
} ผลลัพธ์
เมื่อโปรแกรมข้างต้นทำงาน มันจะให้ผลลัพธ์ดังต่อไปนี้ −
Enter Fahrenheit: 100 Celsius: 37.777779