We use Gnu 2.1.73 and SciTE
fprintf('\nThis program solves the equation ax^2+bx+c=0 for x.\n\n');
a = input('Enter the coefficient a: ');
b = input('Enter the coefficient b: ');
c = input('Enter the coefficient c: ');
if(a==b==c==0)
fprintf('all possible solutions\n');
elseif(a==b==0)
fprintf('no possible solutions\n');
elseif(b^2-4*a*c < 0)
fprintf('no real solutions\n');
elseif(b^2-4*a*c ==0)
x = -b/(2*a)
fprintf('%3.2f.\n', x);
elseif(b^2-4*a*c > 0)
x1 = (-b+(((b^2)-4*a*c)^(1/2)))/(2*a)
x2 = (-b-(((b^2-4*a*c)^(1/2))))/(2*a)
fprintf('The quadratic equation has two solutions:');
disp([x1 x2]);
end;
2006-09-04
17:39:28
·
4 answers
·
asked by
Anonymous
in
Science & Mathematics
➔ Engineering
fprintf('\nThis program solves the equation ax^2+bx+c=0 for x.\n\n');
a = input('Enter the coefficient a: ');
b = input('Enter the coefficient b: ');
c = input('Enter the coefficient c: ');
(d = b^2+4*a*c);
if (a==b==c==0)
fprintf('all possible solutions\n');
elseif (a==b==0)
fprintf('no possible solutions\n');
elseif (d < 0)
fprintf('no real solutions\n');
elseif (d==0)
x = -b/(2*a)
fprintf('The quadratic equation has one solution:');
disp([x])
else (d > 0)
(x1 = ((-b+d^1/2)/(2*a)));
(x2 = ((-b-d^1/2)/(2*a)));
fprintf('The quadratic equation has two solutions:');
disp([x1 x2]);
endif;
if i enter 1,0,1or any other combo of numbers is say "all possible solutions"
Also I believe if a=b=c=0 is not the same as a=b=0 because what if it is 0,0,1.
2006-09-04
21:29:18 ·
update #1