• Lenguaje

    Pascal

  • Descripción

    Pide 2 variables por usuario y muestra las operaciones: ángulo, hipotenusa, cateto opuesto y adyacente.

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
program OperacionesConElTeoremaDePitagoras;
uses crt, math;

var operacion : integer;
var a, b, resultado : real;
begin
    write ('Ingresa el valor de a: ');
    readln (a);
    write ('Ingresa el valor de b: ');
    readln (b);
    writeln ('Selecciona el valor de operacion.');
    writeln ('    1.- '#181'ngulo');
    writeln ('    2.- Hipotenusa');
    writeln ('    3.- Cateto opuesto');
    writeln ('    4.- Cateto adyacente');
    write ('    : ');
    repeat
        readln (operacion);
        if (operacion<1) or (operacion>4) then
            write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
    until (operacion>=1) and (operacion<=4);
    resultado := 0;
    if (operacion=1) and (b<>0) then
        begin
            resultado := arctan(a/b)*180.0/PI;
        end;
    if (operacion=1) and (b=0) then
        begin
            writeln ('Error');
        end;
    if operacion=2 then
        begin
            resultado := sqrt(a*a+b*b);
        end;
    if (operacion=3) and (a>=b) then
        begin
            resultado := sqrt(a*a-b*b);
        end;
    if (operacion=3) and (a<b) then
        begin
            writeln ('Error');
        end;
    if (operacion=4) and (b>=a) then
        begin
            resultado := sqrt(b*b-a*a);
        end;
    if (operacion=4) and (b<a) then
        begin
            writeln ('Error');
        end;
    writeln ('Valor de resultado: ', resultado:0:6);
    writeln;
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.