Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Roots of a Quadratic Equation
#include<stdio.h> #include<math.h> int main(void) { double A, B, C, D, X1, X2, P; printf("Enter the values for A, B, C for a quadratic equation Ax^2 + Bx + C = 0"); scanf("%lf %lf %lf",&A,&B,&C); D=(B*B)-(4*A*C); P=sqrt(D); if (D<0) { D=-D; printf("The roots are %lf + %lf i and %lf - %lf i", -B/(2*A), P/(2*A), -B/(2*A), P/(2*A)); //Since the roots are imaginary for D<0, so the roots must be complex and in the form a+bi //sqrt( ) function is used to calculate the square root and is defined inside math.h } else { X1 = (-B + P)/2*A; X2 = (-B - P)/2*A; printf("The roots are %lf and %lf", X1, X2); } }
run
|
edit
|
history
|
help
0
Click 5
Hello World C++ - minimal
IAR compiler bug test code
pow implementation
finding factor
DeltaX campus recruitment
Dejalo a la Suerte
Estocasticos V1.1
cast operator
Median of two sorted arrays