Skip to content

Commit e87edcc

Browse files
authored
Create Temperature Conversion Using Functions
1 parent 7b45e5b commit e87edcc

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Humza Khawar
3+
Printing temperature through functions
4+
5+
*/
6+
7+
#include<stdio.h>
8+
9+
int celsius(int temp); //this returns temperature in celsius
10+
int fahrenheit(int temp); //this returns temperature in fahrenheit
11+
12+
int main() {
13+
14+
printf("\nTemp(C)\t| Temp(F)|\n------------------\n");
15+
16+
for (int i = 0; i <= 100 ; i+=10)
17+
{
18+
printf(" %3d\t| %5d |\n", i, fahrenheit(i));
19+
20+
}
21+
printf("_________________|\n");
22+
23+
printf("\nTemp(F)\t| Temp(C)|\n------------------\n");
24+
25+
for (int j = 32; j <= 212 ; j+=10)
26+
{
27+
printf(" %d\t| %5d |\n", j, celsius(j));
28+
}
29+
printf("_________________|\n");
30+
31+
return 0;
32+
33+
}
34+
35+
int fahrenheit(temp) {
36+
37+
int converted_temp = (temp*9/5)+32 ;//returns temperature in fahrenheit
38+
39+
return converted_temp;
40+
}
41+
int celsius(temp) {
42+
43+
int converted_temp = (9/5)*(temp - 32);//returns temperature in celsius
44+
45+
return converted_temp;
46+
}
47+

0 commit comments

Comments
 (0)