C program of Temperature conversion Celsius to Fahrenheit vice versa

Mr Coder September 4, 2012 9

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 C program of temperature conversion 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 C program of Temperature Conversion. If you have any issues with the logic or code ask us in form of comments.

9 Comments »

  1. yashwanth kumar September 4, 2012 at 11:45 pm - Reply

    Thank U for the post…

  2. http://cheaprbs.tumblr.com September 5, 2012 at 3:10 pm - Reply

    Itˇs in reality a great and useful piece of information. Iˇm glad that you simply shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  3. windows 7 key September 12, 2012 at 6:49 pm - Reply

    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?

  4. Michael Robert Brown September 15, 2012 at 6:05 am - Reply

    Can I use some of the content from your site on mine? I will make sure to link back to it :)

    • Mr Coder September 15, 2012 at 6:57 am - Reply

      Yes, you can use it.

  5. news for cheaper burberry tobacco October 13, 2012 at 4:35 am - Reply

    Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me.

  6. wow gold October 21, 2012 at 3:48 am - Reply

    Hi, constantly i used to check web site posts here early in the daylight, for the reason that i like to gain knowledge of more and more.

  7. Elisabeth Madueno November 4, 2012 at 1:59 pm - Reply

    Did the Jonathan Ames letter come yet? I signed up in January and that i seriously definitely hope I didn’t miss it. Is there a way I’m able to study it if it did already come?

  8. Zoila Hunzelman November 6, 2012 at 7:02 pm - Reply

    This Weblog deserves a lot more attention than it really is getting correct now

Leave A Response »