Sunday, September 17, 2017

Convert Fahrenheit to Celsius | Convert Celsius to Fahrenheit

Problem

Write two functions in a program of C language to convert:

  • Function 1: Fahrenheit to Celsius
  • Function 2: Celsius to Fahrenheit

Code


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void ftoc();
void ctof();

int main()
{
ftoc();
        ctof();
    
printf ("\n\nPress any key to exit.");
getch();
return 0;
}

void ftoc()
{
float f,c;
printf ("Enter temperature in Fahrenheit: ");
scanf ("%f",&f);

c = 5.0 / 9.0 * (f-32.0);

printf ("Temperature in celsius: %f",c);
}

void ctof()
{
float f,c;
printf ("\n\nEnter temperature in celsius: ");
scanf ("%f",&c);

f = ((9.0 / 5.0 * c) + 32.0);

printf (" Temperature in celsius: %f",f);
}

Output

Convert Fahrenheit to Celsius | Convert Celsius to Fahrenheit
Convert Fahrenheit to Celsius | Convert Celsius to Fahrenheit

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact