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. void printTableHeader(int tableNum);
  21. void printTable(int TableNum, float temperature1, float temperature2);
  22.  
  23. int main(void) {
  24.  
  25. printTableHeader(1);
  26. for (int i=0; i<101; i++) {
  27. float fahrenheitRetVal=toFahrenheit(i);
  28. printTable(1,i,fahrenheitRetVal);
  29. }
  30.  
  31. printTableHeader(2);
  32. for (int i=32; i<213; i++) {
  33. float celsiusRetVal=toCelsius(i);
  34. printTable(2,i,celsiusRetVal);
  35. }
  36.  
  37. return 0;
  38. }
  39.  
  40. //**************************************************************
  41. // Function: toCelsius
  42. //
  43. // Purpose: Receives a temperature in fahrenheit, converts it
  44. // to Celsius and returns the converted value
  45. //
  46. // Parameters:
  47. //
  48. // temp - input temperature in fahrenheit
  49. //
  50. // Returns: temp_convert - input temperature in celsius
  51. //
  52. //**************************************************************
  53. float toCelsius(float fahrenheitTemp){
  54. float celsiusTemp=(fahrenheitTemp - 32) * 5/9;
  55. return celsiusTemp;
  56. }
  57. //**************************************************************
  58. // Function: toFahrenheit
  59. //
  60. // Purpose: Receives a temperature in celsius, converts it
  61. // to Fahrenheit and returns the converted value
  62. //
  63. // Parameters:
  64. //
  65. // temp - input temperature in celsius
  66. //
  67. // Returns: temp_convert - input temperature in fahrenheit
  68. //
  69. //**************************************************************
  70. float toFahrenheit(float celsiusTemp){
  71. float fahrenheitTemp=(celsiusTemp * 9/5) + 32;
  72. return fahrenheitTemp;
  73. }
  74.  
  75. //**************************************************************
  76. // Function: printTableHeader
  77. //
  78. // Purpose: Prints the initial table header information.
  79. //
  80. // Parameters: none
  81. //
  82. // Returns: void
  83. //
  84. //**************************************************************
  85.  
  86. void printTableHeader (int tableNum)
  87. {
  88.  
  89. if (tableNum==1){
  90. // print the table header
  91. printf("\nCelsius Fahrenheit\n");
  92. printf("------------------------ \n");
  93. }
  94. else if (tableNum==2){
  95. // print the table header
  96. printf("\nFahrenheit Celsius\n");
  97. printf("------------------------ \n");
  98. }
  99.  
  100. } // printHeader
  101.  
  102. //*************************************************************
  103. // Function: printTable
  104. //
  105. // Purpose: Prints out all the temperature information
  106. // in a nice and orderly table format.
  107. //
  108. //*************************************************************
  109. void printTable (int tableNum, float temperature1, float temperature2)
  110. {
  111.  
  112. // print the temperature
  113. if (tableNum==1){
  114. printf("%.2f %.1f \n",
  115. temperature1, temperature2);
  116. }
  117. else if (tableNum==2){
  118. printf("%.1f %.2f \n",
  119. temperature1, temperature2);
  120. }
  121. }
  122.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Celsius Fahrenheit
------------------------ 
0.00   32.0 
1.00   33.8 
2.00   35.6 
3.00   37.4 
4.00   39.2 
5.00   41.0 
6.00   42.8 
7.00   44.6 
8.00   46.4 
9.00   48.2 
10.00   50.0 
11.00   51.8 
12.00   53.6 
13.00   55.4 
14.00   57.2 
15.00   59.0 
16.00   60.8 
17.00   62.6 
18.00   64.4 
19.00   66.2 
20.00   68.0 
21.00   69.8 
22.00   71.6 
23.00   73.4 
24.00   75.2 
25.00   77.0 
26.00   78.8 
27.00   80.6 
28.00   82.4 
29.00   84.2 
30.00   86.0 
31.00   87.8 
32.00   89.6 
33.00   91.4 
34.00   93.2 
35.00   95.0 
36.00   96.8 
37.00   98.6 
38.00   100.4 
39.00   102.2 
40.00   104.0 
41.00   105.8 
42.00   107.6 
43.00   109.4 
44.00   111.2 
45.00   113.0 
46.00   114.8 
47.00   116.6 
48.00   118.4 
49.00   120.2 
50.00   122.0 
51.00   123.8 
52.00   125.6 
53.00   127.4 
54.00   129.2 
55.00   131.0 
56.00   132.8 
57.00   134.6 
58.00   136.4 
59.00   138.2 
60.00   140.0 
61.00   141.8 
62.00   143.6 
63.00   145.4 
64.00   147.2 
65.00   149.0 
66.00   150.8 
67.00   152.6 
68.00   154.4 
69.00   156.2 
70.00   158.0 
71.00   159.8 
72.00   161.6 
73.00   163.4 
74.00   165.2 
75.00   167.0 
76.00   168.8 
77.00   170.6 
78.00   172.4 
79.00   174.2 
80.00   176.0 
81.00   177.8 
82.00   179.6 
83.00   181.4 
84.00   183.2 
85.00   185.0 
86.00   186.8 
87.00   188.6 
88.00   190.4 
89.00   192.2 
90.00   194.0 
91.00   195.8 
92.00   197.6 
93.00   199.4 
94.00   201.2 
95.00   203.0 
96.00   204.8 
97.00   206.6 
98.00   208.4 
99.00   210.2 
100.00   212.0 

Fahrenheit Celsius
------------------------ 
32.0   0.00 
33.0   0.56 
34.0   1.11 
35.0   1.67 
36.0   2.22 
37.0   2.78 
38.0   3.33 
39.0   3.89 
40.0   4.44 
41.0   5.00 
42.0   5.56 
43.0   6.11 
44.0   6.67 
45.0   7.22 
46.0   7.78 
47.0   8.33 
48.0   8.89 
49.0   9.44 
50.0   10.00 
51.0   10.56 
52.0   11.11 
53.0   11.67 
54.0   12.22 
55.0   12.78 
56.0   13.33 
57.0   13.89 
58.0   14.44 
59.0   15.00 
60.0   15.56 
61.0   16.11 
62.0   16.67 
63.0   17.22 
64.0   17.78 
65.0   18.33 
66.0   18.89 
67.0   19.44 
68.0   20.00 
69.0   20.56 
70.0   21.11 
71.0   21.67 
72.0   22.22 
73.0   22.78 
74.0   23.33 
75.0   23.89 
76.0   24.44 
77.0   25.00 
78.0   25.56 
79.0   26.11 
80.0   26.67 
81.0   27.22 
82.0   27.78 
83.0   28.33 
84.0   28.89 
85.0   29.44 
86.0   30.00 
87.0   30.56 
88.0   31.11 
89.0   31.67 
90.0   32.22 
91.0   32.78 
92.0   33.33 
93.0   33.89 
94.0   34.44 
95.0   35.00 
96.0   35.56 
97.0   36.11 
98.0   36.67 
99.0   37.22 
100.0   37.78 
101.0   38.33 
102.0   38.89 
103.0   39.44 
104.0   40.00 
105.0   40.56 
106.0   41.11 
107.0   41.67 
108.0   42.22 
109.0   42.78 
110.0   43.33 
111.0   43.89 
112.0   44.44 
113.0   45.00 
114.0   45.56 
115.0   46.11 
116.0   46.67 
117.0   47.22 
118.0   47.78 
119.0   48.33 
120.0   48.89 
121.0   49.44 
122.0   50.00 
123.0   50.56 
124.0   51.11 
125.0   51.67 
126.0   52.22 
127.0   52.78 
128.0   53.33 
129.0   53.89 
130.0   54.44 
131.0   55.00 
132.0   55.56 
133.0   56.11 
134.0   56.67 
135.0   57.22 
136.0   57.78 
137.0   58.33 
138.0   58.89 
139.0   59.44 
140.0   60.00 
141.0   60.56 
142.0   61.11 
143.0   61.67 
144.0   62.22 
145.0   62.78 
146.0   63.33 
147.0   63.89 
148.0   64.44 
149.0   65.00 
150.0   65.56 
151.0   66.11 
152.0   66.67 
153.0   67.22 
154.0   67.78 
155.0   68.33 
156.0   68.89 
157.0   69.44 
158.0   70.00 
159.0   70.56 
160.0   71.11 
161.0   71.67 
162.0   72.22 
163.0   72.78 
164.0   73.33 
165.0   73.89 
166.0   74.44 
167.0   75.00 
168.0   75.56 
169.0   76.11 
170.0   76.67 
171.0   77.22 
172.0   77.78 
173.0   78.33 
174.0   78.89 
175.0   79.44 
176.0   80.00 
177.0   80.56 
178.0   81.11 
179.0   81.67 
180.0   82.22 
181.0   82.78 
182.0   83.33 
183.0   83.89 
184.0   84.44 
185.0   85.00 
186.0   85.56 
187.0   86.11 
188.0   86.67 
189.0   87.22 
190.0   87.78 
191.0   88.33 
192.0   88.89 
193.0   89.44 
194.0   90.00 
195.0   90.56 
196.0   91.11 
197.0   91.67 
198.0   92.22 
199.0   92.78 
200.0   93.33 
201.0   93.89 
202.0   94.44 
203.0   95.00 
204.0   95.56 
205.0   96.11 
206.0   96.67 
207.0   97.22 
208.0   97.78 
209.0   98.33 
210.0   98.89 
211.0   99.44 
212.0   100.00