-
Notifications
You must be signed in to change notification settings - Fork 0
/
New Text Document.с
80 lines (76 loc) · 1.12 KB
/
New Text Document.с
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
float CtoF(float t);
float CtoK(float t);
float KtoC(float t);
float KtoF(float t);
float FtoC(float t);
float FtoK(float t);
int main(int argc, char **argv[])
{
float temp=atof(argv[1]);
char system;
if (argc==3)
{
system=argv[2][0];
}
if(system=='C' || argc==2)
{
if (temp < -273.15)
{
printf("Invalid input\n");
}
else
{
printf("Celcium -> %.2f C %.2f K %.2f F\n", temp, CtoK(temp), CtoF(temp));
}
}
if(system=='F' || argc==2)
{
if (temp<-459.67)
{
printf("Invalid input\n");
}
else
{
printf("Fahrenheit -> %.2f C %.2f K %.2f F\n", FtoC(temp), FtoK(temp), temp);
}
}
if(system=='K' || argc==2)
{
if (temp<0)
{
printf("Invalid input\n");
}
else
{
printf("Kelvin -> %.2f C %.2f K %.2f F\n", KtoC(temp), temp, KtoF(temp));
}
}
return 0;
}
float CtoF(float t)
{
return t*1.8+32;
}
float CtoK(float t)
{
return t+273.15;
}
float KtoC(float t)
{
return t-273.15;
}
float KtoF(float t)
{
return CtoF(KtoC(t));
}
float FtoC(float t)
{
return (t-32)/1.8;
}
float FtoK(float t)
{
return CtoK(FtoC(t));
}