Program Persamaan Kuadrat dengan metode numerik menggunakan C++


#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{ double i,j,p,n,k,a,b,c,fa,fb,fc;
cout<<“persamaan : x^p + nx + k = 0″<<endl;
cout<<“masukkan nilai p (pangkat)  : “;cin>>p;
cout<<“masukkan nilai n            : “;cin>>n;
cout<<“masukkan nilai k (konstanta): “;cin>>k;
cout<<endl<<endl;
cout<<“persamaan yang dipakai adalah”<<endl;
cout<<“x^”<<p<<” + (“<<n<<“)x + (“<<k<<“) = 0”;
cout<<endl<<endl;
cout<<“masukkan sembarang angka  : “;cin>>a;
cout<<“masukkan sembarang angka  : “;cin>>b;
cout<<“masukkan jumlah inetrupsi : “;cin>>j;
fa = pow(a,p) + n*a + k;
fb = pow(b,p) + n*b + k;
if (fa*fb>0)
{
cout<<“angka yang anda masukkan tadi salah ! “<<endl;
cout<<“masukkan lagi sembarang angka < 0 : “;cin>>a;
cout<<“masukkan lagi sembarang angka > 0 : “;cin>>b;
cout<<“masukkan jumlah inetrupsi : “;cin>>j;
fa = pow(a,p) + n*a + k;
fb = pow(b,p) + n*b + k;
}
else
{
c = (a+b)/2;
fc = pow(c,p) + n*c + k;
}
cout<<“susunan a,b,c,fa,fb,fc “<<endl;
cout<<a<<”     “<<b<<”     “<<c<<”     “<<fa<<”     “<<fb<<”     “<<fc<<endl;
i=1;
while ((a*b*fc != 0)&(i<=j))
{
if (fa*fc <0)
{
b = c;
fb = fc;
}
else
{
a = c;
fa = fc;
}
c = (a+b)/2;
fc = pow(c,p) + n*c + k;
i=i+1;
cout<<a<<”     “<<b<<”     “<<c<<”     “<<fa<<”     “<<fb<<”     “<<fc<<endl<<endl;
}
cout<<“Dari perhitungan sesat diatas, didapatkan salah satu nilai ‘x’ adalah : “<<a<<“.”<<endl;
cout<<“Untuk mengetahui nilai x yang lain silahkan coba angka interval yg lain”;
getch ();
}

3 comments

    1. jangan asal copas gan.. lihat juga penggunaan tanda kutip dan petik.. dilihat dari font aja udah beda.. learn by error🙂

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