-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.c
49 lines (47 loc) · 1.36 KB
/
source.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
double converttemp(int from,int to,double temp) {
double result1 = 0;
if (from == 0) {
if (to == 1) {
//c to f
result1 = (temp*(9/5))+32;
} else if (to == 2) {
//c to k
result1 = temp+273.15;
}
} else if (from == 1) {
if (to == 0) {
//f to c
result1 = (temp-32)*(5/9);
} else if (to == 2) {
//f to k
result1 = (temp-32)*(5/9)+273.15;
}
} else if (from == 2) {
if (to == 0) {
//k to c
result1 = temp-273.15;
} else if (to == 1) {
//k to f
result1 = (temp-273.15)*(9/5)+32;
}
}
return result1;
}
int main() {
int op;
int op1;
double temperature;
char tem[3] = "CFK";
printf("Temperature Calculator\n-------------\nConvert from...\n[0] Celsius\n[1] Fahrenheit\n[2] Kelvin\nOption> ");
scanf("%d",&op);
printf("Convert to...\n[0] Celsius\n[1] Fahrenheit\n[2] Kelvin\nOption> ");
scanf("%d",&op1);
printf("Temperature value: ");
scanf("%lf",&temperature);
if (op == op1) {
printf("genius...it's %lf%c",temperature,(char)tem[op1]);
} else {
printf("Result: %lf%c",converttemp(op,op1,temperature),(char)tem[op1]);
}
}