Menentukan Persamaan Kuadrat (Akar Imajiner)

Program :


#include <iostream.h>
#include <math.h>
class kuadrat {
private :
int a, b, c;
long int disk;
float x1, x2;
public :
void input ();
float akar ();
};
kuadrat :: input (){
cout<<"Masukkan nilai a :";
cin>>a;
cout<<"Masukkan nilai b :";
cin>>b;
cout<<"Masukkan nilai c :";
cin>>c;
}
float kuadrat :: akar (){
disk = b*b - 4*a*c;
if(a=0){

cout<<"Bukan persamaan kuadrat";}
else if (disk > 0){
x1 = b + sqrt(disk)/2*a;
x2 = b - sqrt(disk)/2*a;
}
else if (disk = 0){
x1 = b/2*a;
x2 = x1;
}
else {
cout<<"akar imajiner";
}
cout<<"nilai x1 = "<<x1<<" dan nilai x2 = " << x2;
}
int main(){
kuadrat x ;
x.input ();
x.akar ();
cout<<endl;
}

Posted on April 12, 2011, in Alprog. Bookmark the permalink. Tinggalkan komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

%d blogger menyukai ini: