C program of Temperature conversion Celsius to Fahrenheit vice versa

C program of Temperature conversion Celsius to Fahrenheit vice versa

440
10
SHARE

C program of Temperature conversion from Celsius to Fahrenheit and vice versa : I have written a choice driven C program for temperature conversion which converts temperature from Celsius to Fahrenheit and vice versa and also prints the temperature conversion table (generalized i.e. you can print temperatures from any range to any range, also i have generalized it more to ask the difference between two temperatures while printing table values). C Program of temperature conversion is quite easy if we know the basic concepts of temperature conversions i.e. temperature conversion formulas. Aha.. Not asking you to remember as Google is always there to help you out. But still i have searched that for you:

Fahrenheit to Celsius
(°F – 32) x 5/9 = °C
Celsius to Fahrenheit
(°C × 9/5) + 32 = °F

 

Example: Convert 26° Celsius to Fahrenheit

First: 26° × 9/5 = 234/5 = 46.8
Then: 46.8 + 32 = 78.8° F

Example: Convert 98.6° Fahrenheit to Celsius

First: 98.6° – 32 = 66.6
Then: 66.6 × 5/9 = 333/9 = 37° C

Now let us see how to write a which converts Celsius to Fahrenheit and vice verse and prints user driven temperature conversion table.

Note :

Platform : C Language

Compiler : Dev C++

C program to convert Celsius to Fahrenheit and Vice verse :

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
float c,f,tempmin,tempmax,diff;
float i;
int choice,ch;
int main()
{
    printf("----------------------------------------------------\n");
    printf("-------------Made by C codechamp--------------------\n");
    printf("----------------------------------------------------\n\n");
    printf("\t C PROGRAM OF Temperature Conversion\n\n");
    label1:
    printf("\n\n1. Convert Celsius to fahrenheit \n");
    printf("2. Convert Farenheit to Celsius \n");
    printf("3. Print Temp Conversion Table \n");
    printf("4. Exit\n\n");
    printf("\n\n\nPlease enter the choice :  ");
    scanf("%i",&choice);

	switch(choice)
        {
        case 1:printf("\n\n\nEnter temperature in celsius : ");
		        scanf("%f",&c);
                f=((9.0/5.0) * c) + 32.0;
                printf("\n\nThe temprature in fahrenheit is %f \n\n ",f);
                printf("\n\nWanna use the program again...\n\n1. Yes \n2. No\n\n\n");
                scanf("%i",&ch);
                if(ch==1)
                goto label1;
                if(ch==2)
                break;
        case 2:printf("\n\n\nEnter temperature in Fahrenheit : ");
                scanf("%f",&f);
                c=((f-32)*5)/9;
                printf("\n\nThe temperature in celsius id %f \n\n",c);
                printf("\n\nWanna use the program again...\n\n1. Yes \n2. No\n\n\n");
                scanf("%i",&ch);
                if(ch==1)
                goto label1;
                if(ch==2)
                break;
        case 3: label2:
                printf("\n\nEnter starting temp range in table(celcius) : ");
                scanf("%f",&tempmin);
                printf("\n\nEnter end temp range to be displayed : ");
                scanf("%f",&tempmax);
                printf("\n\nEnter the difference between consecutive temps to be displayed : ");
                scanf("%f",&diff);
                if((tempmin>tempmax&&diff>0)||(tempmin<tempmax&&diff<0)){
                printf("\n\nEnter the correct range");
                goto label2;
                }
                else
                {
                printf("\n*******************************************\n");
                printf("\tTemperature Conversion Table");
                printf("\n*******************************************\n");
                printf("\n\nCelcius\t\tFahrenheit\n");
                if(tempmin<=tempmax&&diff>0)
                for(i=tempmin;i<=tempmax;i=i+diff)
                {
                 f=((9.0/5.0) * i) + 32.0; 
                 printf("%f\t\t%f\n",i,f);
                 }
                if(tempmin>tempmax&&diff<0)
                for(i=tempmin;i>=tempmax;i=i+diff)
                {
                 f=((9.0/5.0) * i) + 32.0; 
                 printf("%f\t\t%f\n",i,f);
                 }
                 }
                printf("\n\nWanna use the program again...\n\n1. Yes \n2. No\n\n\n");
                scanf("%i",&ch);
                if(ch==1)
                goto label1;
                if(ch==2)
                break; 
        case 4:break;
        default:
                printf("\n\nPlease enter correct choice\n\n");
                goto label1;
        }
system("pause");
getch();
return 0;
}

We hope you all have enjoyed the of Temperature Conversion. If you have any issues with the logic or code ask us in form of comments.

10 COMMENTS

  1. F*ckin� tremendous things here. I�m very glad to see your post. Thanks a lot and i’m looking forward to contact you. Will you kindly drop me a mail?

LEAVE A REPLY