Viết chương trình giải phương trình ax2 + bx + c = 0 Với các hệ số a,b,c được nhập từ bàn phím.Bằng PASCAL nha !
0 bình luận về “Viết chương trình giải phương trình ax2 + bx + c = 0 Với các hệ số a,b,c được nhập từ bàn phím.Bằng PASCAL nha !”
Program Bai_lam; Uses crt; Var a,b,c,d,x,x1,x2:real; Begin 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); Write(‘Phuong trinh co hai nghiem: ‘); Writeln(‘ x1=’,x1:4:2,’ va x2=’,x2:4:2); End; End; Readln; End.
Program Bai_lam;
Uses crt;
Var a,b,c,d,x,x1,x2:real;
Begin
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);
Write(‘Phuong trinh co hai nghiem: ‘);
Writeln(‘ x1=’,x1:4:2,’ va x2=’,x2:4:2);
End;
End;
Readln;
End.