• Lenguaje

    Pascal

  • Descripción

    Solicite 3 números y que permita al usuario seleccionar la operación que desea que realice con los dígitos, entre los cuales se encuentra: 1.- suma, 2.- resta, 3.- multiplicación y 4.- división. Mostrar al usuario el resultado y el tipo de operación realizada.

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

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.- Suma');
    writeln ('    2.- Resta');
    writeln ('    3.- Multiplicaci'#162'n');
    writeln ('    4.- Divisi'#162'n');
    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 then
        begin
            writeln ('Suma');
            resultado := a+b;
        end;
    if operacion=2 then
        begin
            writeln ('Resta');
            resultado := a-b;
        end;
    if operacion=3 then
        begin
            writeln ('Multiplicaci'#162'n');
            resultado := a*b;
        end;
    if (operacion=4) and (b<>0) then
        begin
            writeln ('Divisi'#162'n');
            resultado := a/b;
        end;
    if (operacion=4) and (b=0) then
        begin
            writeln ('Divisi'#162'n');
            writeln ('Indeterminaci'#162'n');
        end;
    writeln ('Valor de resultado: ', resultado:0:6);
    writeln;
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.