• Lenguaje

    Pascal

  • Descripción

    Calcula los valores de x1 y x2 de una ecuación cuadrática usando la fórmula genral.

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

var a, b, c, discriminante, x1 : real;
var x2 : 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);
    discriminante := b*b-4.0*a*c;
    if discriminante<0 then
        begin
            discriminante := -discriminante;
            writeln ('Soluciones imaginarias');
        end
    else
        begin
            writeln ('Soluciones reales');
        end;
    if a<>0 then
        begin
            x1 := (-b+sqrt(discriminante))/2.0/a;
            x2 := (-b-sqrt(discriminante))/2.0/a;
        end
    else
        begin
            x1 := 0;
            x2 := 0;
            writeln ('No es una ecuaci'#162'n cuadr'#160'tica');
        end;
    writeln ('Valor de discriminante: ', discriminante:0:6);
    writeln ('Valor de x1: ', x1:0:6);
    writeln ('Valor de x2: ', x2:0:6);
    writeln;
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.