Diketahui persamaan kuardrat AX2+BX+C=0.
Buatlah masing – masing fungsi untuk menentukan akar – akarnya
bila D>0, D=0, dan D<0. Buat juga fungsi utama untuk memangil fungsi diatas untuk persamaan berikut :
X2 + 5x+3=0
X2-5X-3=0
X2+X+3=0
X2-X+3=0


Dengan menggunkan fungsi acuan :
#include
#include
#include
pkd (double *A, double *B, double *C);
void main()
{
clrscr();
double a, b, c, d;
double ds, xam1, xam2, r, i;
long double f1, f2, f3, f4;
cout<<"a : "; cin>>a;
cout<<"b : "; cin>>b;
cout<<"c : "; cin>>c;
ds=pkd(&a,&b,&c);
if (ds > 0)
{xam1 = (-b + sqrt(ds)) / (2 * a);
xam2 = (-b - sqrt(ds)) / (2 * a);
cout<<"Real: "< cout<<"x1 = "< cout<<"x2 = "< else
if (ds ==0){
xam1 = -b / (2*a);
xam2 = xam1;
cout<<"Kembar : "< cout<<"x1= "< cout<<"x2= "< else{
r = -b / (2*a);
i=sqrt(fabs(ds))/(2*a);
cout<<"Kompleks"< cout<<"x1 = "< cout<<"x2 = "< f1=a * a + 5 * b + 3 ;
f2=a * a - 5 * b - 3 ;
f3=a * a + b + 3;
f4=a*a-b+3;
cout<<"fungsi Utama 1 : "< cout<<"fungsi Utama 2 : "< cout<<"fungsi Utama 3 : "< cout<<"fungsi Utama 4 : "< getch();
}
pkd(double *A, double *B, double *C)
{
return((*B)*(*B)-4*(*A)*(*C));
}



Dengan menggunkan fungsi nilai :
#include
#include
#include
pkd (double *A, double *B, double *C);
void main()
{
clrscr();
double a, b, c, d;
double ds, xam1, xam2, r, i;
long double f1, f2, f3, f4;
cout<<"a : "; cin>>a;
cout<<"b : "; cin>>b;
cout<<"c : "; cin>>c;
ds=pkd(&a,&b,&c);
if (ds > 0)
{ xam1 = (-b + sqrt(ds)) / (2 * a);
xam2 = (-b - sqrt(ds)) / (2 * a);
cout<<"Real: "< cout<<"x1 = "< cout<<"x2 = "< else
if (ds ==0){
xam1 = -b / (2*a);
xam2 = xam1;
cout<<"Kembar : "< cout<<"x1= "< cout<<"x2= "< else{
r = -b / (2*a);
i=sqrt(fabs(ds))/(2*a);
cout<<"Kompleks"< cout<<"x1 = "< cout<<"x2 = "< f1=a * a + 5 * b + 3 ;
f2=a * a - 5 * b - 3 ;
f3=a * a + b + 3;
f4=a*a-b+3;
cout<<"fungsi Utama 1 : "< cout<<"fungsi Utama 2 : "< cout<<"fungsi Utama 3 : "< cout<<"fungsi Utama 4 : "< getch();
}
pkd(double *A, double *B, double *C)
{
return((*B)*(*B)-4*(*A)*(*C));
}

0 komentar:

Posting Lama Beranda

Blogger Template by Blogcrowds