Program menentukan akr" persamaan kuadrat
Algoritma...
ANALISIS
Input : A,
B, C
Proses
:mencari persamaan akar-akar kuadrat
Output :
akar-akar kuadrat
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++(class)
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
class faktorial
{
public:
int proses();
private:
int A, B, C;
long disk;
float x1, x2;
};
int faktorial::proses(){
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";
}
}
int main(int argc, char** argv) {
faktorial x;
x.proses();
return 0;
}
Flowchart:
Tidak ada komentar:
Posting Komentar