Question: Starting code: #include #include #define GUESS_THRESHOLD 0.000000001 #define EXIT_VALID 0 #define EXIT_BADINPUT 1 #define EXIT_DISCRIMINANT_NEGATIVE 2 #define EXIT_DISCRIMINANT_ZERO 3 int main(); double myreaddouble(); // Provide
Starting code:
#include
#include
#define GUESS_THRESHOLD 0.000000001
#define EXIT_VALID 0
#define EXIT_BADINPUT 1
#define EXIT_DISCRIMINANT_NEGATIVE 2
#define EXIT_DISCRIMINANT_ZERO 3
int main();
double myreaddouble();
// Provide prototype for mysqrt here
// Provide prototype for myabs
double getroot(double a, double b, double c, int positive);
int main()
{
double a, b, c;
double result;
//DEBUG CASE #1 (does the myreaddouble function work?)
/*
while(1)
{
double in;
in = myreaddouble();
printf("read %lf ", in);
if(in == 0)
{
printf("terminating on zero ");
return 0;
}
}
*/
//DEBUG CASE #2 (does the myabs function work?)
/*
while(1)
{
double in;
in = myreaddouble();
printf("read %lf - the absolute value of that is %lf ", in,
myabs(in));
if(in == 0)
{
printf("terminating on zero ");
return 0;
}
}
*/
//DEBUG CASE #3 (does the squareroot function work?)
/*
while(1)
{
double in;
in = myreaddouble();
printf("read %lf - the square root of that is %lf ", in, mysqrt(in));
if(in == 0)
{
printf("terminating on zero ");
return 0;
}
}
*/
printf("This program solves a quadratic equation using the quadratic
formula. ");
printf("For the form ax^2 + bx + c = 0 please enter the following: ");
printf("a=");
a = myreaddouble();
printf("b=");
b = myreaddouble();
printf("c=");
c = myreaddouble();
//You could uncomment this to debug the values or a b and c:
//printf("a b c %lf %lf %lf ", a, b, c);
result = getroot(a, b, c, 1);
printf("The positive root is %lf ", result);
result = getroot(a, b, c, 0);
printf("The negative root is %lf ", result);
return 0;
}
/*
* This function reads a 'double' from the keyboard (standard intput)
* and returns it.
*/
double myreaddouble()
{
//TODO: Implement this function.
return 0;
}
//TODO: You must provide the comments for mysqrt here.
//TODO: You must implement the function mysqrt here.
//TODO: Remember, mysqrt takes a single parameter as a double,
// and it also returns a double that is the square root
// for that number.
// The squareroot of 0 is 0.
// The squareroot of a negative results in:
// {
// printf("mysqrt cannot accept negative numbers. ");
// exit(EXIT_BADINPUT);
// }
//
//This is the algorithm to use for estimating the square root:
//Given input 'n':
//
// Perform input validation on n. (Not negative)
// If n is zero, then shortcircuit and return zero immediately.
//
// Let guess be n.
// Let the next movementDistance be n/2
//
// While the absolute value of (guess^2 - n) is greater than
GUESS_THRESHOLD:
// If the guess^2 is less than n
// Let the guess be guess + movementDistance
// Otherwise
// Let the guess be guess -movementDistance
// Let the movementDistance be divided by two
//
// Return the value of guess. (It is now within the GUESS_THRESHOLD)
//
//
//TODO: Start the function mysqrt right HERE
double mysqrt(double n)
{
//TODO: Implement this function.
return 0;
}
/*
* This function returns the absolute value of a provided double.
* ie, 123 returns 123
* -456 returns 456
* 0 returns 0
*/
double myabs(double n)
{
//TODO: Implement this function.
//HINT: This can be done in as little as 1 lines, but
// the obvious solution takes 3 lines if made easily readable.
return 0;
}
//TODO: You must provide the comments for getroot here.
//TODO: You must implement the function getroot here.
//HINT: Remember that if the discriminant is negative then you'll print
the message:
// "The discriminant is negative. There are no real roots. "
// and exit with EXIT_DISCRIMINANT_NEGATIVE
// If the discriminant is zero then you'll print:
// "The discriminant is zero. There is only one real root. "
// and exit with EXIT_DISCRIMINANT_ZERO
//HINT: Remember that if the variable positive is set to zero, then
// you return the negative case from the quadratic formula.
// Otherwise, you return the positive case from the quadratic
formula.
//HINT: To do b^2 you simply evaluate (b*b) since C doesn't let you use
the '^' operator like that.
double getroot(double a, double b, double c, int positive)
{
//TODO: Implement this function.
return 0;
}





ITCS 2116-C Programming- Fall 2017 Homework 4 Objectives . Practice the use of functions in C to process data. . Practice the implementation of flow of control statements . Practice the use of arrays in C functions In this assignment you will write two (2) C programs. Each program will be in its own source code file. The following set of instructions provide the s Make sure to test each program thoroughly before submitting it. pedific requirements for each program Read all instructions carefully, including the Wikipedia artides mentioned below, before you start working on your programs. For Program 1, you are given a template program. You should compile, run and carefully examine the code before making any changes. Program 1 ( 60 points) Write a program that calculates the roots of a quadratic equation using the quadratic formula. The user will be prompted for three real number coefficients, a, b, and c. The program will then calculate the roots. A sample program execution would be the following, where the user input is italicized and highlighted: This program soives quadratie equation using the quadratie tormuia. For the torm ax2-0 piease nter the tollowing a-21.34 b-32.5467 56 782 The positive root s 1.038169 The negative root is-2.563319 Quadratic Equation & Formula A quadratic equation with real or complex coefficients has two solutions, called roots. These two solutions may or may not be distinct, and they may or may not be real. From the Quadratic Equation, having the form of
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
