Program for 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

 Live Demo

#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

 Live Demo

#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

Updated on: 20-Sep-2019

559 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements