0

Why am I not getting any output

#include <stdio.h> int main() { int a,b,c,D; double x,y; printf("enter the value of a,b,c"); scanf("%d%d%d",&a,&b,&c); D = b*b-4*a*c; if (D > 0) { printf("the roots are distinct and real"); x = (-b+(D))/2*a; y = (-b-(D))/2*a; printf("the roots are: %f%f",x,y); } else if (D==0) { printf("roots are equal"); x = y = -b/2*a; printf("roots are :%f%f",x,y); } else { printf("roots are imaginary"); } return 0; } https://code.sololearn.com/cKe3jXGEO7LF/?ref=app

21st Nov 2023, 3:48 PM
doraemon cartoon
doraemon cartoon - avatar
1 Answer
+ 2
doraemon cartoon when I run the program, I get output. However, I noticed that the calculation is wrong. Due to mathematical order of operations, the formulas in lines 12 and 13 are incorrectly multiplying by a, instead of dividing by a. Furthermore, due to integer math rules in C, the results will be wrong. The formulas need to be done in floating point. This can be accomplished by changing at least one element of the formula into a floating point value, like the constant 2 -> 2.0. x = (-b+D)/(2.0*a); y = (-b-D)/(2.0*a);
21st Nov 2023, 6:26 PM
Brian
Brian - avatar