Posted By

bhart on 10/27/13


Tagged

Converter cold hot celsius fahrenheit


Versions (?)

Celsius to Fahrenheit


 / Published in: C
 

Celsius to Fahrenheit

  1. /****************************************************
  2. * c2f.c
  3. *
  4. * Computer Science 50
  5. * Brendan Hart
  6. *
  7. * Converts Celsius into Fahrenheit
  8. *
  9. * Demostrates float data types, equations, math
  10. *****************************************************/
  11.  
  12. #include <cs50.h>
  13. #include <stdio.h>
  14.  
  15. int main(void)
  16. {
  17. // ask temperature in Celsius
  18. printf("What is the temperature in Celsius?\n");
  19.  
  20. // get temperature in Celsius
  21. float c = GetFloat();
  22.  
  23. // equation converts temperature in Celsius to Fahrenheit
  24. // declares variable f as temperature in Celsius
  25. float f = ((9.0 / 5.0)*c + 32.0);
  26.  
  27. // prints results to .1 decimal appoximation
  28. printf("The temperature in Fahrenheit is %.1f degrees\n", f);
  29. return 0;
  30. }

Report this snippet  

You need to login to post a comment.