Lập trình giải phương trình ax^2+bx+c =0 Với a=0 và a khác 0 pascal nha Mình cần gấp lắm giúp mình với ạ!!!

2 câu trả lời

Program BTH;
Uses CRT;
Var a,b,c,D,x,x1,x2: real;
Begin
  Clrscr;
  Writeln('Giai phuong trinh bac 2: ');
  Write('Nhap he so a: '); readln(a);
  Write('Nhap he so b: '); readln(b);
  Write('Nhap he so c: '); readln(c);
  If a=0 then
    If b=0 then
      If c=0 then
        Writeln('Phuong trinh co vo so nghiem')
      Else Writeln('Phuong trinh vo nghiem')
    Else Writeln('Phuong trinh co mot nghiem: x: ',-c/b: 4: 2)
  Else
    Begin
      D:=b*b-4*a*c;
      If D=0 then Writeln('Phuong trinh co nghiem kep: x: ',-b/(2*a): 4: 2)
      Else
        If D<0 then Writeln('Phuong trinh vo nghiem')
        Else
           Begin
             x1:=(-b-sqrt(D))/(2*a);
             x2:=(-b+sqrt(D))/(2*a);
             Writeln('Phuong trinh co 2 nghiem la x1: ',x1:4:2 ,' va x2: ',x2:4:2);
           End;
     End;
Readln
End.

Program GIAI_PHUONG_TRINH_BAC_NHAT;Uses crt;Var a,b,x: real;Begin  Clrscr;  Writeln('GIAI PHUONG TRINH BAC NHAT: AX + B=0');  Writeln('------------------------------------------------------------');  Write ('Nhap a= '); readln(a);  Write ('Nhap b= '); readln(b);  If(a=0) then    If(b=0) then Writeln(' Phuong trinh co vo so nghiem')      Else writeln(' Phuong tring vo nghiem')  Else Writeln('Phuong trinh co nghiem x=',-b/a: 4: 2);  Readln

end

Câu hỏi trong lớp Xem thêm