QuadraticEquation

This commit is contained in:
2021-04-27 10:59:39 +05:30
parent 6def7ef4a4
commit 6ac9870f54
3 changed files with 31 additions and 1 deletions

View File

@@ -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
View 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

Binary file not shown.