Guys Please Help! I am having problems with this program. I can't clear an error that I'm getting, but I'm not even sure that this program takes care of what was assigned. Let me know if you can provide an assistance!
Below is the assignment and what I have written. Bare with me, I'm a beginner!
The real roots of a quadratic equation can be calculated using the quadratic formula as:
_______
root 1 = (-b + b2 - 4ac ) / 2a
_______
root 2 = (-b - b2 - 4ac ) / 2a
However, if a user entered a value of zero for a, the division by 2a would result in an error when the program is run. Another error occurs when the value of the term b2 - 4ac, which is called the discriminant, is negative, because the square root of a negative number cannot be taken.
Using the algorithm below, write a C program that solves for the two roots of a quadratic equation.
display a program purpose message
display a prompt for the coefficients
accept user input values for a, b, and c
if a = 0 and b = 0 then
display a message saying that the equation is degenerate (has no solution)
else if a = 0 then
calculate the single root equal to -c / b
display the single root
else
calculate the discriminant
if the discriminant > 0 then
solve for both roots using the quadratic formula
display the two roots
else if the discriminant < 0 then
display a message that there are no real roots
else
calculate the repeated root equal to -b / (2a)
display the repeated root
endif
endif*/
#include <stdio.h>
#include <math.h>
void main ()
{
int A, B, C, D, single_root, repeated_root;
double root1, root2;
printf("Please enter 3 integers separated by a space: ");
printf("These numbers will be calculated as A, B and C in a quadratic equation and the output will be the two calculated roots.");
scanf("%d,%d,%d,",&A,&B,&C);
if (A==0&&B==0)
printf ("Since 0 was your input for A and B, the equation has no solution.");
if(A==0)
{ (single_root= -C/B);
printf("Given the value of %d and %d, the single root is equal to %d", C,B,single_root);
}
else (D=B^2-4*A*C);
{
if (D>0)
{ (root1=(-B+sqrt(B^2-4*A*C))/(2*A))
(root2=(-B-sqrt(B^2-4*A*C))/(2*A));
printf("The two roots are %d and %d.",root1, root2);
}
else if (D<0)
printf ("There are no real roots.");
else (repeated_root = -B/(2*A));
printf ("The repeated root is %d.", repeated_root);
}
}
Let me know of anything that might help me, I don't have anyone I can ask for help on this, so I'm hoping any of you guys can help me!
Thanks =)