• Lenguaje

    Pascal

  • Descripción

    Se requiere utilizar una calculadora que pueda realizar operaciones básicas como lo son: suma, resta, multiplicación, división o residuo, para esto se reciben 3 números, el primer número representa al valor 1, el segundo el valor 2 y el último represente la opción del usuario; se deberá mostrar el resultado final de la operación así como la opción elegida.

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

var a, b, operacion, resultado_final : integer;
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');
    writeln ('    5.- Residuo');
    write ('    : ');
    repeat
        readln (operacion);
        if (operacion<1) or (operacion>5) then
            write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
    until (operacion>=1) and (operacion<=5);
    resultado_final := 0;
    if operacion=1 then
        begin
            resultado_final := a+b;
            writeln ('Suma');
        end;
    if operacion=2 then
        begin
            resultado_final := a-b;
            writeln ('Resta');
        end;
    if operacion=3 then
        begin
            resultado_final := a*b;
            writeln ('Multiplicaci'#162'n');
        end;
    if (operacion=4) and (b=0) then
        begin
            writeln ('No se puede obtener la divisi'#162'n');
        end;
    if (operacion=4) and (b<>0) then
        begin
            resultado_final := a div b;
            writeln ('Divisi'#162'n');
        end;
    if (operacion=5) and (b=0) then
        begin
            writeln ('No se puede obtener el residuo');
        end;
    if (operacion=5) and (b<>0) then
        begin
            resultado_final := a mod b;
            writeln ('Residuo');
        end;
    writeln ('Valor de resultado final: ', resultado_final);
    writeln;
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.