fork download
  1. //********************************************************
  2. //
  3. // C Midterm - Question 7
  4. //
  5. // Name: Maya Mahin
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: March 23, 2025
  10. //
  11. // Description: Program which facilitates the conversion of fahrenheit to
  12. // celsius temperatures and vice versa
  13. //
  14. //********************************************************
  15.  
  16. #include <stdio.h>
  17.  
  18. float toCelsius(float fahrenheitTemp);
  19. float toFahrenheit(float celsiusTemp);
  20.  
  21. int main(void) {
  22. for (int i=0; i<101; i++) {
  23. float celsiusRetVal=toCelsius(i);
  24. printf("The temperature in Celsius is: %.1f\n", celsiusRetVal);
  25. }
  26.  
  27. // float fahrenheitRetVal=toFahrenheit(0);
  28. // printf("The temperature in Fahrenheit is: %.1f\n", fahrenheitRetVal);
  29.  
  30. return 0;
  31. }
  32.  
  33. //**************************************************************
  34. // Function: toCelsius
  35. //
  36. // Purpose: Receives a temperature in fahrenheit, converts it
  37. // to Celsius and returns the converted value
  38. //
  39. // Parameters:
  40. //
  41. // temp - input temperature in fahrenheit
  42. //
  43. // Returns: temp_convert - input temperature in celsius
  44. //
  45. //**************************************************************
  46. float toCelsius(float fahrenheitTemp){
  47. float celsiusTemp=(fahrenheitTemp - 32) * 5/9;
  48. return celsiusTemp;
  49. }
  50. //**************************************************************
  51. // Function: toFahrenheit
  52. //
  53. // Purpose: Receives a temperature in celsius, converts it
  54. // to Fahrenheit and returns the converted value
  55. //
  56. // Parameters:
  57. //
  58. // temp - input temperature in celsius
  59. //
  60. // Returns: temp_convert - input temperature in fahrenheit
  61. //
  62. //**************************************************************
  63. float toFahrenheit(float celsiusTemp){
  64. float fahrenheitTemp=(celsiusTemp * 9/5) + 32;
  65. return fahrenheitTemp;
  66. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The temperature in Celsius is: -17.8
The temperature in Celsius is: -17.2
The temperature in Celsius is: -16.7
The temperature in Celsius is: -16.1
The temperature in Celsius is: -15.6
The temperature in Celsius is: -15.0
The temperature in Celsius is: -14.4
The temperature in Celsius is: -13.9
The temperature in Celsius is: -13.3
The temperature in Celsius is: -12.8
The temperature in Celsius is: -12.2
The temperature in Celsius is: -11.7
The temperature in Celsius is: -11.1
The temperature in Celsius is: -10.6
The temperature in Celsius is: -10.0
The temperature in Celsius is: -9.4
The temperature in Celsius is: -8.9
The temperature in Celsius is: -8.3
The temperature in Celsius is: -7.8
The temperature in Celsius is: -7.2
The temperature in Celsius is: -6.7
The temperature in Celsius is: -6.1
The temperature in Celsius is: -5.6
The temperature in Celsius is: -5.0
The temperature in Celsius is: -4.4
The temperature in Celsius is: -3.9
The temperature in Celsius is: -3.3
The temperature in Celsius is: -2.8
The temperature in Celsius is: -2.2
The temperature in Celsius is: -1.7
The temperature in Celsius is: -1.1
The temperature in Celsius is: -0.6
The temperature in Celsius is: 0.0
The temperature in Celsius is: 0.6
The temperature in Celsius is: 1.1
The temperature in Celsius is: 1.7
The temperature in Celsius is: 2.2
The temperature in Celsius is: 2.8
The temperature in Celsius is: 3.3
The temperature in Celsius is: 3.9
The temperature in Celsius is: 4.4
The temperature in Celsius is: 5.0
The temperature in Celsius is: 5.6
The temperature in Celsius is: 6.1
The temperature in Celsius is: 6.7
The temperature in Celsius is: 7.2
The temperature in Celsius is: 7.8
The temperature in Celsius is: 8.3
The temperature in Celsius is: 8.9
The temperature in Celsius is: 9.4
The temperature in Celsius is: 10.0
The temperature in Celsius is: 10.6
The temperature in Celsius is: 11.1
The temperature in Celsius is: 11.7
The temperature in Celsius is: 12.2
The temperature in Celsius is: 12.8
The temperature in Celsius is: 13.3
The temperature in Celsius is: 13.9
The temperature in Celsius is: 14.4
The temperature in Celsius is: 15.0
The temperature in Celsius is: 15.6
The temperature in Celsius is: 16.1
The temperature in Celsius is: 16.7
The temperature in Celsius is: 17.2
The temperature in Celsius is: 17.8
The temperature in Celsius is: 18.3
The temperature in Celsius is: 18.9
The temperature in Celsius is: 19.4
The temperature in Celsius is: 20.0
The temperature in Celsius is: 20.6
The temperature in Celsius is: 21.1
The temperature in Celsius is: 21.7
The temperature in Celsius is: 22.2
The temperature in Celsius is: 22.8
The temperature in Celsius is: 23.3
The temperature in Celsius is: 23.9
The temperature in Celsius is: 24.4
The temperature in Celsius is: 25.0
The temperature in Celsius is: 25.6
The temperature in Celsius is: 26.1
The temperature in Celsius is: 26.7
The temperature in Celsius is: 27.2
The temperature in Celsius is: 27.8
The temperature in Celsius is: 28.3
The temperature in Celsius is: 28.9
The temperature in Celsius is: 29.4
The temperature in Celsius is: 30.0
The temperature in Celsius is: 30.6
The temperature in Celsius is: 31.1
The temperature in Celsius is: 31.7
The temperature in Celsius is: 32.2
The temperature in Celsius is: 32.8
The temperature in Celsius is: 33.3
The temperature in Celsius is: 33.9
The temperature in Celsius is: 34.4
The temperature in Celsius is: 35.0
The temperature in Celsius is: 35.6
The temperature in Celsius is: 36.1
The temperature in Celsius is: 36.7
The temperature in Celsius is: 37.2
The temperature in Celsius is: 37.8