• Lenguaje

    Pascal

  • Descripción

    Leer el peso de cuatro esferas (A, B, C, D) de las cuales se sabe que tres son de igual peso y una diferente. Elaborar un algoritmo que determine cuál es la esfera diferente y si es de mayor o menor peso.

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
program PesoDeCuatroEsferas;
uses crt;

var A, B, C, D, peso_diferente : real;
var peso_normal : real;
begin
    write ('Ingresa el valor de A: ');
    readln (A);
    write ('Ingresa el valor de B: ');
    readln (B);
    write ('Ingresa el valor de C: ');
    readln (C);
    write ('Ingresa el valor de D: ');
    readln (D);
    peso_normal := 0;
    peso_diferente := 0;
    if (A=B) and (B=C) then
        begin
            writeln ('D es la esfera diferente.');
            peso_normal := A;
        end
    else
        begin
            peso_diferente := D;
        end;
    if (B=C) and (C=D) then
        begin
            writeln ('A es la esfera diferente.');
            peso_normal := B;
        end
    else
        begin
            peso_diferente := A;
        end;
    if (C=D) and (D=A) then
        begin
            writeln ('B es la esfera diferente.');
            peso_normal := C;
        end
    else
        begin
            peso_diferente := C;
        end;
    if (D=A) and (A=B) then
        begin
            writeln ('C es la esfera diferente.');
            peso_normal := D;
        end
    else
        begin
            peso_diferente := C;
        end;
    if peso_diferente<peso_normal then
        begin
            writeln ('Menor peso.');
        end
    else
        begin
            writeln ('Mayor peso.');
        end;
    writeln ('Valor de peso diferente: ', peso_diferente:0:6);
    writeln ('Valor de peso normal: ', peso_normal:0:6);
    writeln;
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.