Pascal: Giải phương trình bậc 2 dạng đầy đủ. (Có cả trường hợp A#0, Delta >0, delta <0, delta =0)

Program giaiptb2;

Uses Crt;

Var

a, b, c, x1, x2, delta: real;

cont: char;

Begin

clrscr;

write(‘Nhap he so a, b, c: ‘);

readln(a, b, c);

If a=0 then writeln(‘Ban phai nhap he so a#0’)

Else

Begin

delta:=b*b-4*a*c;

If delta<0 then write(‘Phuong trinh vo nghiem!’)

Else

If delta=0 then

Begin

x1:=(-b)/(2*a);

writeln(‘Phuong trinh co nghiem duy nhat: x=’, x1:5:2);

End

Else

Begin

x1:=(-b+sqrt(delta))/2/a;

x2:=(-b-sqrt(delta))/2/a;

writeln(‘Phuong trinh co 2 nghiem phan biet:’);

writeln(‘  x1=’, x1:8:2);

writeln(‘  x2=’, x2:8:2);

End;

End;

readln;

End.

You may also like...