
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Celsius to Fahrenheit Conversion in C++
Given with temperature ‘n’ in Celsius the challenge is to convert the given temperature to Fahrenheit and display it.
Example
Input 1-: 100.00 Output -: 212.00 Input 2-: -40 Output-: -40
For converting the temperature from Celsius to Fahrenheit there is a formula which is given below
T(°F) = T(°C) × 9/5 + 32
Where, T(°C) is temperature in Celsius and T(°F) is temperature in Fahrenheit
Approach used below is as follows
- Input temperature in a float variable let’s say Celsius
- Apply the formula to convert the temperature into Fahrenheit
- Print Fahrenheit
ALGORITHM
Start Step 1 -> Declare a function to convert Celsius to Fahrenheit void cal(float cel) use formula float fahr = (cel * 9 / 5) + 32 print cel fahr Step 2 -> In main() Declare variable as float Celsius Call function cal(Celsius) Stop
Using C
Example
#include <stdio.h> //convert Celsius to fahrenheit void cal(float cel){ float fahr = (cel * 9 / 5) + 32; printf("%.2f Celsius = %.2f Fahrenheit", cel, fahr); } int main(){ float Celsius=100.00; cal(Celsius); return 0; }
Output
100.00 Celsius = 212.00 Fahrenheit
Using C++
Example
#include <bits/stdc++.h> using namespace std; float cel(float n){ return ((n * 9.0 / 5.0) + 32.0); } int main(){ float n = 20.0; cout << cel(n); return 0; }
Output
68
Advertisements