Your problem is assuming that x1 and x2 are integers when you print them out.
Additionally, a,b,c are all likely to be floating point numbers. So read them in as floats. So make your output statement printf("%g and %g\n",x1,x2); Also you can use the sqrt function in line k=sqrt(d); .
HOWEVER: Can I just point out that using the formula given is a horrible way to calculate the roots to a quadratic equation due to the numeric instability of the solution. The "better" way is to calculate x1,x2 and determine which biggest root
(either in terms of magnitude or accuracy as a solution) and use the relationship x1*x2=c/a to get the other root.
There are further tricks to getting better roots from a quadratic equation, particularly if the roots are close, if b^2-4ac is near zero ,e.g a Newton Raphson step etc.
printf("Enter the values of a,b,c:");
d = ((b*b)-(4*a*c));
k = sqrt(d);
x = (-b+k)/(2*a);
y = (-b-k)/(2*a);
printf("The quadratic equation is x = %f and y = %f",x,y);
float re, im;
k = sqrt(d);
re = -b/(2*a);
im = k/(2*a);
printf("The quadratic equation is x=%f+(%fi)\n",re,im);
printf("The quadratic equation equation is y=%f-(%fi)\n",re,im);
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...