-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask 2
90 lines (78 loc) · 2.86 KB
/
task 2
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
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
// Function prototypes
double celsius_to_fahrenheit(double celsius);
double celsius_to_kelvin(double celsius);
double fahrenheit_to_celsius(double fahrenheit);
double fahrenheit_to_kelvin(double fahrenheit);
double kelvin_to_celsius(double kelvin);
double kelvin_to_fahrenheit(double kelvin);
int main() {
int choice;
double temperature, converted_temperature;
printf("Temperature Conversion Program\n");
printf("------------------------------\n");
printf("1. Celsius to Fahrenheit\n");
printf("2. Celsius to Kelvin\n");
printf("3. Fahrenheit to Celsius\n");
printf("4. Fahrenheit to Kelvin\n");
printf("5. Kelvin to Celsius\n");
printf("6. Kelvin to Fahrenheit\n");
printf("Enter your choice (1-6): ");
scanf("%d", &choice);
printf("Enter temperature value: ");
scanf("%lf", &temperature);
switch (choice) {
case 1:
converted_temperature = celsius_to_fahrenheit(temperature);
printf("%.2f Celsius = %.2f Fahrenheit\n", temperature, converted_temperature);
break;
case 2:
converted_temperature = celsius_to_kelvin(temperature);
printf("%.2f Celsius = %.2f Kelvin\n", temperature, converted_temperature);
break;
case 3:
converted_temperature = fahrenheit_to_celsius(temperature);
printf("%.2f Fahrenheit = %.2f Celsius\n", temperature, converted_temperature);
break;
case 4:
converted_temperature = fahrenheit_to_kelvin(temperature);
printf("%.2f Fahrenheit = %.2f Kelvin\n", temperature, converted_temperature);
break;
case 5:
converted_temperature = kelvin_to_celsius(temperature);
printf("%.2f Kelvin = %.2f Celsius\n", temperature, converted_temperature);
break;
case 6:
converted_temperature = kelvin_to_fahrenheit(temperature);
printf("%.2f Kelvin = %.2f Fahrenheit\n", temperature, converted_temperature);
break;
default:
printf("Invalid choice!\n");
break;
}
return 0;
}
// Function to convert Celsius to Fahrenheit
double celsius_to_fahrenheit(double celsius) {
return (celsius * 9 / 5) + 32;
}
// Function to convert Celsius to Kelvin
double celsius_to_kelvin(double celsius) {
return celsius + 273.15;
}
// Function to convert Fahrenheit to Celsius
double fahrenheit_to_celsius(double fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
// Function to convert Fahrenheit to Kelvin
double fahrenheit_to_kelvin(double fahrenheit) {
return (fahrenheit + 459.67) * 5 / 9;
}
// Function to convert Kelvin to Celsius
double kelvin_to_celsius(double kelvin) {
return kelvin - 273.15;
}
// Function to convert Kelvin to Fahrenheit
double kelvin_to_fahrenheit(double kelvin) {
return kelvin * 9 / 5 - 459.67;
}