Program C++ Menghitung Akar Kuadrat

#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{
int a,b,c;
long disk;
float x1,x2;

cout<<“koefesien pankat 2 : “;cin>>a;
cout<<“koefesien pankat 1 : “;cin>>b;
cout<<“koefesien pankat 0 : “;cin>>c;

if(a==0){
cout<<“bukan persamaan kuadrat”<<endl;
cout<<“harga akar = “<<-c/b;}
else{
disk=b*b-4*a*c;
if (disk>0){
x1=-b+sqrt(disk)/(2*a);
x1=-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″<<endl;
cout<<“x1 = “<<x1<<endl;
cout<<“x2 = “<<x2<<endl;}
else
cout<<“Akar imajiner”<<endl;
}
cout<<endl;

system(“PAUSE”);
return EXIT_SUCCESS;
}

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com 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 )

Foto Google+

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

Connecting to %s