Tuesday, May 3, 2011

Program Persamaan Kuadrat

Program Persamaan_Kuadrat;
Uses Wincrt;
Var A,B,C:integer;
    D,X1,X2:real;
Begin
  Writeln('Program Persamaan Kuadrat');
  Writeln('=========================');
  Writeln;
  Write('Masukkan Nilai A: ');readln(A);
  Write('Masukkan Nilai B: ');readln(B);
  Write('Masukkan Nilai C: ');readln(C);
  Writeln;
  D:=sqr(B)-(4*A*C);
  if (D>0) then
    begin
      X1:=(-B+sqrt(D))/2*A;
      X2:=(-B-sqrt(D))/2*A;  
      Writeln('X1= ',X1:4:1,'    ','X2= ',X2:4:1);
    end
  else if (D=0) then
    begin
      X1:=-B/(2*A);
      Writeln('X1=X2=',X1:4:1);
    end
  else
    Writeln('Akar Imajiner!');
End.
Outputnya:

0 comments:

Post a Comment