To write a C program to convert Celsius to Fahrenheit and vice versa.
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.
// 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
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 . . .
While using in-built C-Compiler Use Gear icon for custom Input (i.e. whenever you have to give values to read)
Thus, the C program has been written, executed successfully to calculate temperature conversion from Fahrenheit to Celsius or Celsius to Fahrenheit.
All about java servlets Part-2 What is a website? Website is a collection of related…
Let's train the machine. Machine learning is a growing technology which enables computers to learn…
“Unless you try to do something beyond what you have already mastered, you will never…
Whenever you decide to start coding and you want to become budding coder or programmer…
C components are essential elements of a C program, including comments, preprocessor directives, functions, statements,…
All about java servlets Part-2 What is a website? Website is a collection of related…
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.