I am trying to rewrite a while do loop as a for do loop in Pascal, please is there a way to rewrite the below code into a for loop statement... And determine which is better and why ?
Thanks in advance..
Here is the code
program Quadractics;
uses crt;
const n=10;
VAR
a,b,c,d,e,x1,x2:real;
k:Integer;
BEGIN
k:= 0;
while k<n DO
begin
writeln('Input the values for variables a,b,c');
readln(a,b,c);
e:=2*a;
d:=sqr(b)-(4.0*a*c);
if d>=0 then
begin
x1:=(-b+sqrt(d)) /e;
x2:=(-b-sqrt(d)) /e;
writeln('The resulting roots of the above equation are x1= ', x1 , ' and x2= ', x2);
end
else
begin
write('complex root values are ');
write('x1 = ', '(',-b, '+√',d,')','/',e ,', ');
write('and','; ');
write('x2 = ', '(',-b, '-√',d,')','/',e ,', ');
end;
k:=k+1;
end;
END.