Contoh-Program-C++ - if(D> 0 X1 =-b sqrt(D(2*a X2...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Contoh Program C++ Menghitung akar persamaan kuadrat #include "stdio.h" #include "math.h" int main() { float a, b, c, D, X, X1, X2, XRiil, XImajiner; printf("Perhitungan akar-akar persamaan aX2+bX+c=0\n"); printf("Masukkan nilai koefisien a, b, dan c:\n"); scanf("%f %f %f", &a, &b, &c); D = b*b-4*a*c; printf("Diskriminan = %g\n", D); printf("Akar persamaan %gX2 + %gX + %g = 0 adalah:\n", a, b, c);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (D > 0) { X1 = (-b+sqrt(D))/(2*a); X2 = (-b-sqrt(D))/(2*a); printf("X1 = %g\n", X1); printf("X2 = %g\n", X2); } else if (D == 0) { X = -b/(2*a); printf("X1 = X2 = %g\n", X); } else { XRiil = -b/(2*a); XImajiner = sqrt(-D)/(2*a); printf("Akar imajiner:\n"); printf("X1 = %g+%g*i\n", XRiil, XImajiner); printf("X2 = %g-%g*i\n", XRiil, XImajiner); } return 0; }...
View Full Document

This note was uploaded on 11/14/2011 for the course DDDD h0322 taught by Professor Whoknow during the Spring '11 term at Bina Nusantara University.

Ask a homework question - tutors are online