Place Your Query
-
C Programming
-
- Control flow-based C Programs
- Enjoy Conditional Programming in C using If...else and switch statement.
- Good, Now write a C program to display "Hello World" on the screen.
- Write a C program to display Your Name, Address and City in different lines.
- C program to find sum of n numbers
- Write a C program For Addition of two numbers using Function.
- Write a Program to Find Simple Interest and Compound Interest.
- Write a Program to Convert Celsius To Fahrenheit and Vice Versa.
- Write a Program to Find Area and Perimeter of Circle, Triangle, Rectangle and Square.
- Write a Program to Swap Two Numbers Using Temporary Variables and Without Using Temporary Variables
- Write a C Program to Design a Simple Menu Driven Calculator
- Simple Expression Based C Programs
-
- 7. Components of C language
- 1. Introduction to C Programming Language
- 10. Operator Precedence and Associativity
- 11. Comments in C Programming
- 14. Fundamental Control Structure Statements in C [Part-1]
- 15. Fundamental Control Structure Statements in C [Part-2]
- 16. Looping Statements [Fundamental Control Structure Statements in C. #Part-3]
- 17. Keyword break, continue, return and exit [Fundamental Control Structure Statements in C. #Part-4]
- 2. Computer Languages
- 3. Interpreters vs Compilers vs Assemblers in programming languages
- 4. C Program Structure
- 5. Compile and Execute C Program
- 6. Errors in C Program
- 8. C Datatypes
- 9. Operators in C
- Control flow-based C Programs
- Demystifying Bit Masking: Unlocking the Power of Bitwise Operators in C-Language with best Examples.
- 18. Fundamentals of C Functions
- Show Remaining Articles (3)Collapse Articles
-
-
Java
-
AI ML
-
FAQs
- A Program to find Tokens in C code?
- What are the Common Coding Mistakes.
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python String Functions QAs for Beginner to Pro Part-3
-
Python Interview Questions
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python String Functions QAs for Beginner to Pro Part-3
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
While using in-built C-Compiler Use Gear icon for custom Input (i.e. whenever you have to give values to read)
Result
Thus, the C program has been written, executed successfully to calculate temperature conversion from Fahrenheit to Celsius or Celsius to Fahrenheit.