+ 1
quadratic equation
Hello, What is the wrong with my code thx! https://code.sololearn.com/c4i0dWuX8iJ7/#
2 Réponses
+ 3
1. Move D = b*b-4*a*c; after getting a,b,c values
So,
printf("Enter a b and c:");
scanf("%d %d %d", &a , &b , &c);
D = b*b-4*a*c;
2. Your roots have the same value. Modify them as follow
x1 = (-b+sqrt(D)) / (2*a);
x2 = (-b-sqrt(D)) / (2*a);
3. Roots should be defined as float or double as the roots
are not always integer.
4. Add the following code for the case that D=0
else if (D == 0)
{
x1 = x2 = -b/(2*a);
printf("X1 and X2 are the roots:",x1, x2);
}
5. Add minus symbol in rp = b/2*a;
So, rp = -b/(2*a);
6. What is i(ip) ?
If you want multiply use * operator
i is not declared
Complex number cannot be defined in c. (keep i only for printing)
There are a lot of error in your code...
Try to rewrite your code
+ 1
https://code.sololearn.com/c4i0dWuX8iJ7
i just rewrote the code