Program Mencari persamaan kuadrat

#include "stdio.h"
#include "math.h"

int main()
{
float a, b, c, D, X, X1, X2, XRiil, XImajiner;
printf("Nama : afit miranto\n");
printf("NPM : G1D009001\n");
printf("Prodi: Teknik Elektro\n\n");
printf("Program Mencari persamaan kuadrat\n\n");

printf("Perhitungan akar-akar persamaan aX2+bX+c=0\n");
printf("Masukkan nilai koefisien a, b, dan c:\n");
printf("Masukkan nilai koefisien a: "); scanf("%f", &a);
printf("Masukkan nilai koefisien b: "); scanf("%f", &b);
printf("Masukkan nilai koefisien c: "); scanf("%f", &c);

D = b*b-4*a*c;
printf("Diskriminan = %g\n", D);
printf("Akar persamaan %gX^2 + %gX + %g = 0 adalah:\n", a, b, c);
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;
}

Categories:

0 comments:

Post a Comment