Sempurnakan algoritma 3.3. dengan akar imajiner berbentuk : a + bi
dengan a dan b bilangan real dan bila harga : b2-4ac<0
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
class imajiner{
private:
float xRiil;
float xImajiner;
public:
float x;
float y;
float z;
float n;
float a;
float a1;
float a2;
xRiil=p;
xImajiner=q;}
float hasil();};
float imajiner::hasil(){
cout <<"Masukkan Koefisien a: ";
cin>>x;
cout <<"Masukkan Koefisien b: ";
cin>>y;
cout <<"Masukkan Koefisien c: ";
cin>>z;
n = y * y - 4 * x * z;
cout << "Diskriminan= (" << y
<< " * " << y << " - 4 * " << x
<< " + " << z <<") = " << n
<< endl;
cout << "Akar persamaan " << x
<<"x^2 + " << y << "x + " << z
<<" = 0" << endl;
if (n > 0)
{
a1 = (-y+sqrt(n))/(2*x);
a2 = (-y-sqrt(n))/(2*x);
cout << "x1 = " << a1 <<
endl;
cout << "x2 = " << a2 <<
endl;
}
else if (n == 0)
{
a = -y/(2*x);
cout << "x1 = x2 = " << a
<< endl;
}
else
{
xRiil = -y/(2*x);
xImajiner = sqrt(-n)/(2*x);
cout << "Imajiner: " << endl;
cout << "x1 = " << xRiil
<< " + " << xImajiner << " * i "<<
endl;
cout << "x1 = " << xRiil
<< " - " << xImajiner << " * i "<<
endl;
}
}
int main(int argc, char *argv[])
{
imajiner satu;
float p,q;
satu.nilai(p,q);
satu.hasil();
return 0;
}
Berikut programnya:
ABOUT THE AUTHOR
Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible
0 komentar:
Posting Komentar