QuadraticEquation
This commit is contained in:
@@ -19,3 +19,4 @@
|
|||||||
|17 | PositiveOrNegative.c | PositiveOrNegative.exe | WAP to find out a given number is positive, negative or 0 |
|
|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) |
|
|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) |
|
|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 |
|
||||||
29
QuadraticEquation.c
Normal file
29
QuadraticEquation.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
QuadraticEquation.exe
Normal file
BIN
QuadraticEquation.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user