My issue
please solve this
My code
#include <stdio.h>
#include <math.h>
int main() {
int a;
int b;
int c;
double discriminant, root1, root2, realPart, imagPart;
printf("enter coefficients of a, b and c: ");
scanf("%f %f %f", &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("Roots are real and different.\n");
printf("root 1 = %.21f and root 2 = %.21f\n", root1, root2);
}
// condition for real and equal roots
else if (discriminant == 0) {
root1 =root2 = -b / (2 * a);
printf("Roots are real and equal.\n");
printf("Root 1 = Root 2 = %.21f\n", root1);
}
//if roots are not real
else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex and different.\n");
printf("Root 1 = %.21f + %.21fi and root 2 = %.21f - %.21fi\n", realPart, imagPart);
}
return 0;
}
Learning course: Learn C Programming
Problem Link: https://www.codechef.com/learn/course/rcpit-programming-c/RCPITLPC09/problems/LJAJAG25