Write a Program to Convert Celsius To Fahrenheit and Vice Versa.

Aim

To write a C program to convert Celsius to Fahrenheit and vice versa.

Procedure/ Algorithm

Step-1: Start the program execution.

Step-2: Declare f, c, ch.

Step-3: Get the value of choice whether Celsius to Fahrenheit conversion or vice versa.

Step-4: If choice=1, input the value of Fahrenheit and convert that to Celsius using the formula (f-32.0)/1.8).

Step-5: If choice=2, input the value of Fahrenheit and convert that to Celsius using the formula (c*1.8)+32.0).

Step-6: Print the results of f and c.

Step-7: Stop the program execution.

Code


// author milndbhatt
#include<stdio.h>
#include<conio.h>
int main()
{
float f,c;
int ch;

printf("\nEnter the choice:\n1.Fahrenheit to celcius\n2.celcius to fahreheit: choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter fahrenheit:"); scanf("%f",&f);
printf("\nEquivalent celcius value is %f",((f-32.0)/1.8));
break;

case 2: printf("\nEnter celcius:"); scanf("%f",&c);
printf("\nEquivalent fahrenheit value is %f",((c*1.8)+32.0));
break;

default: printf("\nEnter the correct choice:"); break;
}
return 0;
} // end main

Output

ROUND-1:
Enter the choice:
1.Fahrenheit to celcius
2.celcius to fahreheit: choice:1

Enter fahrenheit:230

Equivalent celcius value is 110.000000
--------------------------------
Process exited after 8.733 seconds with return value 0
Press any key to continue . . .

=================================================================================

ROUND-2:


Enter the choice:
1.Fahrenheit to celcius
2.celcius to fahreheit: choice:2

Enter celcius:40

Equivalent fahrenheit value is 104.000000
--------------------------------
Process exited after 5.406 seconds with return value 0
Press any key to continue . . .

Run Directly on in-built C-Compiler

Result

Thus, the C program has been written, executed successfully to calculate temperature conversion from Fahrenheit to Celsius or Celsius to Fahrenheit.


Recommended Readings

https://ezylearning.in/e-landing-page/1-introduction-to-c-language/
https://ezylearning.in/e-landing-page/11-comments-in-c-programming/
https://ezylearning.in/e-landing-page/fundamental-control-structure-statements-in-c-part-2/
Milind Bhatt

A Tech Educator, youtuber and blogger. Having in total 22 years of teaching experience in the field of computer science, data science, artificial intelligence and machine learning.

View Comments

  • Hi to all, the contents existing at this web site are truly amazing for people knowledge, well, keep up the good work fellows.

Share
Published by
Milind Bhatt
Essential Web Terminology for Servlets

Essential Web Terminology for Servlets

All about java servlets Part-2 What is a website? Website is a collection of related…

2 years ago
Understanding Machine Learning

Understanding Machine Learning

Let's train the machine. Machine learning is a growing technology which enables computers to learn…

2 years ago
Demystifying Bit Masking: Unlocking the Power of Bitwise Operators in C-Language with best Examples.

Demystifying Bit Masking: Unlocking the Power of Bitwise Operators in C-Language with best Examples.

“Unless you try to do something beyond what you have already mastered, you will never…

2 years ago
What are the Common Coding Mistakes.

What are the Common Coding Mistakes.

Whenever you decide to start coding and you want to become budding coder or programmer…

2 years ago

7. Components of C language

C components are essential elements of a C program, including comments, preprocessor directives, functions, statements,…

2 years ago

Essential Web Terminology for Servlets

All about java servlets Part-2 What is a website? Website is a collection of related…

2 years ago