Menghitung √b²-4*a*c

Posted: April 18, 2010 in Daspro
Tags:

#include<conio.h>

#include<math.h>

#include<iostream.h>

#include<windows.h>

void setcolor(unsigned short color)

{

HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(hCon,color);

}

main()

{

float x,x1,x2,a,b,c;

clrscr;

setcolor(12);cout<<“Masukan Nilai a : “;cin>>a;

setcolor(12);cout<<“Masukan Nilai b : “;cin>>b;

setcolor(12);cout<<“Masukan Nilai c : “;cin>>c;

x = b*b-4*a*c;

if(x<0)

{setcolor(2);cout<<“Alim Akh !!!”<<endl;

}

else

{

x1 = (-b+sqrt(x))/(2*a);

x2 = (-b-sqrt(x))/(2*a);

setcolor(12);cout<<“Hasil x1 : “<<x1<<endl;

setcolor(12);cout<<“Hasil x2 : “<<x2<<endl;

}

getch();

}

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