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