Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I really appreiciate any help with my assignment. The following is my assignment

ID: 3640771 • Letter: I

Question

I really appreiciate any help with my assignment. The following is my assignment instructions

DUE: March 21st, 2012 (at the beginning of the class).
NOTE: Submit both the text file and the output file. Also, save the two files in your account (in your sd0XX folder) in the UNIX Lab by the due date. Failure to do so will result in losing up to 50 points for each lab.

Find the roots of the equation of the form ax2 +bx+ c =0. Ask the user to input a, b and c. Calculate the discriminant = b2 – 4ac.
a. If the discriminant is less than zero, display the message “The roots are imaginary”.
b. Otherwise, calculate the roots and display them as follows:
i. If the roots are the same, display “The roots are the same” and display the single calculated root.
ii. If they are different, display “The roots are different” and display the calculated roots.
Use the squareRoot function in chapter 8.

The following is the square root function from chapter 8

#include <stdio.h>

float absoluteValue (float x)
{
if (x < 0)
x = -x;
return (x);
}

float squareRoot (float x)
{
const float epsilon = .00001;
float guess = 1.0;

while ( absoluteValue (guess * guess - x) >= epsilon )


guess = ( x / guess + guess ) / 2.0;

return guess;
}
int main (void)
{
printf (" squareroot (2.0) = %f ", squareRoot (2.0));
printf (" squareroot (144.0) = %f ", squareRoot (144.0));
printf (" squareroot (2.0) = %f ", squareRoot (144.0));

getch();
}

Ok I incorporated the square root function from abpve into my program
and wrote the following:

#include <stdio.h>

float absoluteValue (float x)
{
if (x < 0)
x = -x;
return (x);
}

float squareRoot (float x)
{
const float epsilon = .00001;
float guess = 1.0;

while ( absoluteValue (guess * guess - x) >= epsilon )


guess = ( x / guess + guess ) / 2.0;

return guess;
}
int main (void)
{
int a,b,c,y,z,Z;

printf ("We will find the roots of the equation of the form ax^2 +bx+ c =0 ");
printf ("First enter a value for a ");

scanf ("%i", &a);

printf ("Next enter a value for b ");

scanf ("%i", &b);

printf ("Next enter a value for c ");

scanf ("%i", &c);

y = (-b + (squareRoot(b*b*-4*a*c)))/2*a;

z = (-b - (squareRoot(b*b*-4*a*c)))/2*a;

Z = b*b*(-4*a*c);

if (Z < 0)
printf (" The roots are imaginary ");
else if ( y==z)
printf ("The roots are the same and are equal to %i ", y);
else if ( y != z )
printf ("The roots are different and are equal to %i and %i ", y,z);


getch();
}

I am able to compile the program witth out errors but it does not run correctly:

I am pretty sure it has to do with this part of the program

y = (-b + (squareRoot(b*b*-4*a*c)))/2*a;

z = (-b - (squareRoot(b*b*-4*a*c)))/2*a;

Z = b*b*(-4*a*c);

I do not think I can use the Square root function like this, but then I am stuck on how to use this function to get my program to operate correctly. I Appreciate any help with this program. Thanks very, very much, Bill

Explanation / Answer

PS: Please rate the answer The formula is not correct. You are multiplying b^2 and -4ac y = (-b + (squareRoot(b*b*-4*a*c)))/2*a; z = (-b - (squareRoot(b*b*-4*a*c)))/2*a; Z = b*b*(-4*a*c); Use this y = (-b + (squareRoot(b*b - 4*a*c)))/2*a; z = (-b - (squareRoot(b*b - 4*a*c)))/2*a; Z = b*b - (4*a*c);