Viết thuật toán cho bài toán Giải phương trình bật 2 ax^2 + b +c = 0 Input? Output? Liệt kê? Vẽ sơ đồ? 04/08/2021 Bởi Piper Viết thuật toán cho bài toán Giải phương trình bật 2 ax^2 + b +c = 0 Input? Output? Liệt kê? Vẽ sơ đồ?
#include<bits/stdc++.h>using namespace std;long long a,b,c,d;float s,x,x1,x2;int main(){ freopen(“EQN.inp”,”r”,stdin); freopen(“EQN.out”,”w”,stdout); cin>>a>>b>>c; d=b*b-4*a*c; if(d<0) cout<<“NO SOLUTION”; if(d==0){x=-b*1.0/(2*a); cout<<fixed<<setprecision(4); cout<<x;} if(d>0){x1=(-b-sqrt(d))*1.0/(2*a); x2=(-b+sqrt(d))*1.0/(2*a); cout<<fixed<<setprecision(4); cout<<x1<<” “<<x2;}} Input: 1 2 3 Output: NO SOLUTION Input: 1 3 2 Output: -1 -2 Input: 1 2 1 Output: -1 Bình luận
input: a, b, c output: x program oken;uses crt;var a,b,c: longint; x: real;begin clrscr; write(‘Nhap cac so a,b,c: ‘); readln(a,b,c); writeln(a,’*x^2+’,b,’+’,c,’=0′); x:=sqrt(abs((-b-c))/a); writeln(‘Ket qua: ‘,x:0:4); readln;end. Bình luận
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
float s,x,x1,x2;
int main()
{
freopen(“EQN.inp”,”r”,stdin);
freopen(“EQN.out”,”w”,stdout);
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d<0) cout<<“NO SOLUTION”;
if(d==0){x=-b*1.0/(2*a);
cout<<fixed<<setprecision(4);
cout<<x;}
if(d>0){x1=(-b-sqrt(d))*1.0/(2*a);
x2=(-b+sqrt(d))*1.0/(2*a);
cout<<fixed<<setprecision(4);
cout<<x1<<” “<<x2;}
}
Input: 1 2 3
Output: NO SOLUTION
Input: 1 3 2
Output: -1 -2
Input: 1 2 1
Output: -1
input: a, b, c
output: x
program oken;
uses crt;
var a,b,c: longint;
x: real;
begin
clrscr;
write(‘Nhap cac so a,b,c: ‘); readln(a,b,c);
writeln(a,’*x^2+’,b,’+’,c,’=0′);
x:=sqrt(abs((-b-c))/a);
writeln(‘Ket qua: ‘,x:0:4);
readln;
end.