Finding roots of quadratic equation

Finding roots of a quadratic equation, roots of quadratic equation is already the formula.

Algorithm Quadratic Equations :

Reading A, B, and C, and then calculates the roots of a quadratic equation Ax ^ 2 Bx C = 0 by determining the value of disc = B * B-4 * A * C first then later look for the roots of the quadratic equation

Deklarasi

A, B, C            : integer                       {koefisien-koefisien persamaan}

disk                  : longint                      {nilai diskriminan}

x1, x2 : real                            {nilai-nilai akar untuk disk>=0}

Deskripsi

read (A, B, C)

disk ß B*B– 4*A*C

if (A = 0) then write (‘Bukan Persamaan Kuadrat’)

else if disk > 0 then

x1 ß-B + sqrt (disk)/2*A

x2 ß-B – sqrt(disk)/2*A

else if disk = 0 then

x1 ß-B/2*A

x2 ß x1

else write (‘Akar imajiner’)

end if

write (x1,x2)

program C++
#include <iostream.h>

#include <math.h>

#include <conio.h>

main() {

int   A, B, C;

long  disk;

float x1, x2;

cout << "Koefisien pangkat 2   : "; cin >> A;

cout << "Koefisien pangkat 1   : "; cin >> B;

cout << "Koefisien pangkat 0   : "; cin >> C;

if (A == 0) {

cout << "bukan pers. kuadrat.\n";

cout << "Harga akar = " << -C/B; }  else {

disk = B*B - 4*A*C;

if (disk > 0) {

x1 = -B+sqrt(disk)/(2*A);

x2 = -B-sqrt(disk)/(2*A);

cout << "diskriminan = " << disk << endl;

cout << "x1 = " << x1 << endl;

cout << "x2 = " << x2 << endl;

}  else if (disk == 0) {

x1 = -B/(2*A);   x2 = x1;

cout << "diskriminan = 0\n";

cout << "x1 = " << x1 << endl;

cout << "x2 = " << x2 << endl;

} else cout << "Akar imajiner";

}

getch();

return 0;

}
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: