ViijayScript: 06/10/16

Friday 10 June 2016

#Programs to #Convert #Celsius to #Fahrenheit in #C #C++ #Java C# #Python

Hello netizens, On this post I am going to tell #Programs to #Convert #Celsius to #Fahrenheit in #C #C++ #Java C# #Python.

Program in C:

#include <stdio.h>
#include<conio.h>
void main()
{
float c,f;
/*To convert Centigrade to Fahrenheit*/
printf(“Enter the temperature in centigrade:”);
scanf(“%f”,&c);
f=1.8*c+32;
printf(“\n\t%.2f Centigrade=%.2f Fahrenheit”,c,f);
/*To convert Fahrenheit to centigrade*/
printf(“\n\nEnter the temperature in Fahrenheit:”);
scanf(“%f”,&f);
c=(f-32)/1.8;
printf(“\n\t%.2f Fahrenheit=%.2f Centigrade”,f,c);
getch();
}

Program in C++:

# include<iostream>
using namespace std;
void main()
{
int choice;
float f, c;
cout<<“To convert your temperature from Celsius to Fahrenheit press 1:”<<endl;
cout<<“To convert your temperature from Fahrenheit to Celsius press 2:”<<endl;
cout<<“Now Enter Your Choice: “;
cin>>choice;
if(choice==1)
{
cout<<“enter your temperature in Celsius : “;
cin>>c;
f = (9.0/5.0)*c + 32;
cout<<“Your temperature in Fahrenheit is = “<<f<<“\n”;
}
else if(choice==2)
{
cout<<“Enter Your Temperature In Fahrenheit : “;
cin>>f;
c = (5.0/9.0)*(f-32.0);
cout<<“Your temperature in Celsius is = “<<c<<“\n”;
}
}

Program in Java:

import java.io.*;
class CONVERSION_OF_TEMPERATURE
{
private double fahrenheit,celcius;
public static void main(String args[])throws IOException
{
System.out.println(” THIS PROGRAM IS FOR CONVERSION OF TEMPERATURE FROM .”);
CONVERSION_OF_TEMPERATURE obj=new CONVERSION_OF_TEMPERATURE();
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println(“ENTER YOUR CHOICE”);
System.out.println(“1> FAHRENHEIT TO CELCIUS CONVERSION”);
System.out.println(“2> CELCIUS TO FAHRENHEIT CONVERSION”);
int c=Integer.parseInt(input.readLine());
switch(c)
{
case 1:
{
System.out.println(“ENTER THE TEMPERATURE IN FAHRENHEIT”);
System.out.print(“USER INPUT : “);
try
{
obj.fahrenheit=Double.parseDouble(input.readLine());
}
catch(Exception b)
{
System.out.println(“”);
System.out.println(“\t\tERROR FOUND : YOU HAVE TO ENTER ONLY INTEGERS PLEASE RERUN THE PROGRAM”);
System.exit(0);
}
obj.celcius=5/9.0*(obj.fahrenheit-32);
System.out.println(“”);
System.out.println(“THE TEMPERATURE IN CELCIUS IS “+obj.celcius);
break;
}
case 2:
{
System.out.println(“ENTER THE TEMPERATURE IN CELCIUS”);
System.out.print(“USER INPUT : “);
try
{
obj.celcius=Double.parseDouble(input.readLine());
}
catch(Exception b)
{
System.out.println(“”);
System.out.println(“\t\tERROR FOUND : YOU HAVE TO ENTER ONLY INTEGERS PLEASE RERUN THE PROGRAM”);
System.exit(0);
}
obj.fahrenheit=1.8*(obj.celcius+ 32);
System.out.println(“”);
System.out.println(“THE TEMPERATURE IN FAHRENHEIT IS “+obj.fahrenheit);
break;
}
default:
{
System.out.println(“ENTERED WRONG DATA THE PROGRAM WILL TERMINATE”);
}
}
}
}

Program in C#:

1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Text;
5. namespace program
6. {
7. class Program
8. {
9. static void Main(string[] args)
10. {
11. int celsius, faren;
12. Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
13. celsius = int.Parse(Console.ReadLine
());
14. faren = (celsius * 9) / 5 + 32;
15. Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
16. Console.ReadLine();
17. }
18. }
19. }

Program in Python:

Script to convert Celsius to Fahrenheit:
celsius = float(raw_input(“Enter the temperature in Celsius: “));
Fahrenheit = (9.0/5.0)*celsius + 32.0;
print ‘The temperature in Fahrenheit:’, Fahrenheit;
Script to convert Fahrenheit to Celsius:
Fahrenheit = float(raw_input(“Enter the temperature in Fahrenheit: “));
Celsius = (5.0/9.0)*(Fahrenheit – 32.0);
print ‘The temperature in Celsius:’, Celsius;

If our post is helpful then please share it with your dear and near ones.

Scan this QR Code on LinkedIn

Scan this QR Code on LinkedIn