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; printf("Enter the values for A, B, C for a quadratic equation Ax2 + Bx + C = 0"); scanf("%lf %lf %lf",&A,&B,&C); D=(B*B)-(4*A*C); if (D<0) { D=-D; printf("The roots are %lf + %lf i and %lf - %lf i", -B/(2*A), sqrt(D)/(2*A), -B/(2*A), sqrt(D)/(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 + sqrt(D))/2*A; X2 = (-B - sqrt(D))/2*A; printf("The roots are %lf and %lf", X1, X2); } }
run
|
edit
|
history
|
help
0
Lee hora y suma un segundo
correccion
Herout (67) - 5
Bubles: secuencia descenciente de números
pointer
Funciones: MandelBrot
Základy UDP
Bucles: Triángulo de asteriscos lateral izquierdo
lab7OOP 0.1
Vectores: Llena vector con números al azar