Deklarasi
a,b,c: integer
D,x1,x2,p,q real
Algoritma
read (a,b,c)
D<-b*b-4*a*c
x1<-(-b+sqrt(D))/2*a
x2<-(-b-sqrt(D))/2*a
p<-(-b/2*)a
q<-sqrt(-D)/2*a
if (D>0) then
{write (x1)
write (x2)
write ('2 akar real') }
if (D==0) then
{write (x1)
write ('1 akar real') }
if (D<0) then
{write (x1,x2)
write ('2 akar imajiner') }
CODING
/***PROGRAM MENENTUKAN JENIS AKAR PERSAMAAN KUADRAT***/
#include<iostream>
#include<math.h>
using namespace std;
int main() {
/**DEKLARASI**/
int a,b,c;
float D,x1,x2,p,q;
/*ALGORITMA*/
cout<<"PROGRAM MENENTUKAN JENIS AKAR PERSAMAAN KUADRAT"<<endl;
cout<<"a="; cin>>a;
cout<<"b="; cin>>b;
cout<<"c="; cin>>c;
D=b*b-4*a*c;
x1=(-b+sqrt(D))/2*a;
x2=(-b-sqrt(D))/2*a;
p=-b/2*a;
q=sqrt(-D)/2*a;
if (D>0)
{cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl;
cout<<"2 akar real"<<endl;
}
if (D==0)
{cout<<"x1=x2="<<x1<<endl;
cout<<"1 akar real"<<endl;
}
if (D<0)
{cout<<"x1="<<p<<"+"<<q<<"i"<<endl;
cout<<"x2="<<p<<"-"<<q<<"i"<<endl;
cout<<"2 akar imajiner"<<endl;
}
system("PAUSE");
}
KELUARAN
Download program disini https://drive.google.com/open?id=1bmnTaLg42lLwxo33DyeEj9c3MtslWhY1
lopyu cang (BAGAS)
ReplyDelete