diff --git a/Order Of Programs.md b/Order Of Programs.md index 42d2c8f..98ca507 100644 --- a/Order Of Programs.md +++ b/Order Of Programs.md @@ -18,4 +18,5 @@ |16 | MaximumNo4.c | MaximumNo4.exe | WAP to find out maximum out of three numbers using nested if..else | |17 | PositiveOrNegative.c | PositiveOrNegative.exe | WAP to find out a given number is positive, negative or 0 | |18 | Grade.c | Grade.exe | Use else if ladder statements to find out the result grade from the percentage (Mentioned in file of the program) | -|19 | Admission.c | Admission.exe | to find the eligibility of admission for a professional course based on the following criteria (Mentioned in file of the program) | \ No newline at end of file +|19 | Admission.c | Admission.exe | to find the eligibility of admission for a professional course based on the following criteria (Mentioned in file of the program) | +|20 | QuadraticEquatic. | QuadraticEquatic.exe | WAP to calculate the root of a Quadratic Equation | \ No newline at end of file diff --git a/QuadraticEquation.c b/QuadraticEquation.c new file mode 100644 index 0000000..8948e5d --- /dev/null +++ b/QuadraticEquation.c @@ -0,0 +1,29 @@ +// WAP to calculate the root of a Quadratic Equation. + +void main() { + double a, b, c, discriminant, root1, root2, realPart, imagPart; + printf("Enter coefficients a, b and c: "); + scanf("%lf %lf %lf", &a, &b, &c); + + discriminant = b * b - 4 * a * c; + + // condition for real and different roots + if (discriminant > 0) { + root1 = (-b + sqrt(discriminant)) / (2 * a); + root2 = (-b - sqrt(discriminant)) / (2 * a); + printf("root1 = %.2lf and root2 = %.2lf", root1, root2); + } + + // condition for real and equal roots + else if (discriminant == 0) { + root1 = root2 = -b / (2 * a); + printf("root1 = root2 = %.2lf;", root1); + } + + // if roots are not real + else { + realPart = -b / (2 * a); + imagPart = sqrt(-discriminant) / (2 * a); + printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart); + } +} \ No newline at end of file diff --git a/QuadraticEquation.exe b/QuadraticEquation.exe new file mode 100644 index 0000000..256b998 Binary files /dev/null and b/QuadraticEquation.exe differ