-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversor_de_temperatura.c
More file actions
43 lines (35 loc) · 1.36 KB
/
Copy pathconversor_de_temperatura.c
File metadata and controls
43 lines (35 loc) · 1.36 KB
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
#include <stdio.h>
int temp(int entrada, float temperatura){ //função com entrada de indice e temperatura desejada
int total = 0; //recebera o resultado da CONVERSAO
switch(entrada){ //interruptor //botões
case 1: //botão celcius para Fareinhait
total = temperatura*(1.8) + 32;
break;
case 2: //Botão Fareinhait para Celcius
total = (temperatura - 32) / 1.8;
break;
case 3: //Botão Kelvil para Celcius
total = (temperatura - 273.15);
break;
case 4: //Botão Celcius para Kelvin
total = temperatura + 273.15;
break;
case 5: //Botão Kelvin para Fahrenheit
total = 1.8 * (temperatura-273) +32;
break;
}
return total; //retorna o valor já convertido
}
int main (){
int indice;
float temperatura;
float resultado;
printf("[1] Celsius para Fahrenheit\n[2] Fahrenheit para Celsius\n[3] Kelvin para Celsius\n[4] celsius para kelvin\n[5] kelvin para Fahrenheit\n");
printf("Como deseja converter as temperaturas? ");
scanf("%d" , &indice);
printf("Digite a temperatura: ");
scanf("%f" , &temperatura);
resultado = temp(indice , temperatura);
printf("A temperatura equivalente de %2.f e igual a %2.f", temperatura , resultado);
return 0;
}