-
Lenguaje
Pascal
-
Descripción
Convertir grados Fahrenheit a Celsius y viceversa. El programa deberá leer en primer lugar un número entero que indicará si se va a convertir de grados Fahrenheit a Celsius (1) o de grados Celsius a Fahrenheit (2). Seguidamente leerá el valor de la temperatura, realizará la conversión aplicando la fórmula adecuada e imprimirá el resultado.
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
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
program FahrenheitACelsiusYViceversa;
uses crt;
var opcion : integer;
var resultado, temperatura : real;
begin
write ('Ingresa el valor de temperatura: ');
readln (temperatura);
writeln ('Selecciona el valor de opcion.');
writeln (' 1.- Fahrenheit a Celsius');
writeln (' 2.- Celsius a Fahrenheit');
write (' : ');
repeat
readln (opcion);
if (opcion<1) or (opcion>2) then
write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
until (opcion>=1) and (opcion<=2);
if opcion=1 then
begin
resultado := (temperatura-32)/1.8;
end
else
begin
resultado := 1.8*temperatura+32;
end;
writeln ('Valor de resultado: ', resultado:0:6);
writeln;
write ('Presiona una tecla para terminar . . . ');
readkey;
end.
uses crt;
var opcion : integer;
var resultado, temperatura : real;
begin
write ('Ingresa el valor de temperatura: ');
readln (temperatura);
writeln ('Selecciona el valor de opcion.');
writeln (' 1.- Fahrenheit a Celsius');
writeln (' 2.- Celsius a Fahrenheit');
write (' : ');
repeat
readln (opcion);
if (opcion<1) or (opcion>2) then
write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
until (opcion>=1) and (opcion<=2);
if opcion=1 then
begin
resultado := (temperatura-32)/1.8;
end
else
begin
resultado := 1.8*temperatura+32;
end;
writeln ('Valor de resultado: ', resultado:0:6);
writeln;
write ('Presiona una tecla para terminar . . . ');
readkey;
end.