Write an approximate square root program using nextGuess=(previousGuess+(num/pre
ID: 3647187 • Letter: W
Question
Write an approximate square root program using nextGuess=(previousGuess+(num/previousGuess))/2When next Guess and previous Guess are almost identical The previous Guess to start may be any positive value. After each calculation you will compare nextGuess and previousGuess and if the difference is less than 0.00001 then next Guess is the approximate square root of num. If not , then the value of nextGuess is copied to previousGuess and the calculation is done again.
Please write out an example program for me and tell me what you did step by step.
Explanation / Answer
//SQUARE ROOT GUESTIMATOR //----------------------- //NECESSARY PREPROCESSOR DIRECTIVES #include #include using namespace std; //VOID FUNCTIONS void getValues(float&, float&, bool&); //WILL RECIEVE INPUT VALUES FROM USER. void swap(float&, float&); //WILL SWAP NEXT GUESS AND LAST GUESS IF NEEDED. void newGuess(float, float, float&); //WILL CALCULATE NEXT GUESS. //MAIN PROGRAM int main() { //DECLARED VARIABLES AND FUNCTIONS float ng=0.0; //VARIABLE FOR "NEXT GUESS" float lg=0.0; //VARIABLE FOR "LAST GUESS" float n=0.0; //VARIABLE FOR THE SQUARE ROOT OF A NUMBER float difference=0.0; bool dataok = false; bool done = false; int count=0; getValues(n,lg,dataok); while((done==false)) { newGuess(n,lg,ng); difference = (lg - ng); if ((difference > 0.005) || (difference < -0.005)) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.