Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAMMING: Please Help! Overview: We will program the Babylonian Square Root Method. Let number be the number to get the square root of Start

C PROGRAMMING: Please Help!

Overview:

We will program the Babylonian Square Root Method.

  1. Let number be the number to get the square root of

  2. Start with an estimate of 1.

  3. Recompute estimate = 0.5 * (estimate + number/estimate)

  4. Go back to 3

Stop the looping when either of these is true:

(estimate*estimate) == number The number of iterations gets to 100, the maximum

1. Please copy-and-paste the following files (0 Points):

babylonianSqrt.c

#include  #include  

const int TEXT_LEN = 64;

void obtainFloat (float* fPtr{ ) { char text[TEXT_LEN]; 
 // YOUR CODE HERE }
float squareRoot. (float number, int maxIters, int* numItersPtr 

)

{

float estimate. = 1.0;

// YOUR CODE HERE 

return(estimate);

}

int main ()

{

float f;

float ans;

int numIters = 0;

 obtainFloat(&f); ans = squareRoot(f,100,&numIters); printf("squareRoot(%g) approx. equals %g (found in %d iterations). ", 
 f,ans,numIters ); 
 return(EXIT_SUCCESS); } 

2. Finish obtainFloat() (40 Points):

It should ask the user to enter a number from 0 to 65535, and lets the user enter a number. If the user enters a number outside that range, it asks again. The number is not returned, but number is placed in the address to which fPtr points.

3. Finish squareRoot() (60 Points):

After setting estimate to 1.0, it should loop and recompute estimate with the expression above. Every time it loops, it should increment the integer to which numItersPtr points. The loop should stop when the condition given above is met.

Sample Output:

[instructor@localhost Assign1]$ ./babylonianSqrt Please enter a floating point number (0 - 65535): -7

Please enter a floating point number (0 - 65535): 1000000

Please enter a floating point number (0 - 65535): 9

squareRoot(9) approx. equals 3 (found in 5 iterations).

[instructor@localhost Assign1]$ ./babylonianSqrt Please enter a floating point number (0 - 65535): 100

squareRoot(100) approx. equals 10 (found in 7 iterations).

[instructor@localhost Assign1]$ ./babylonianSqrt

Please enter a floating point number (0 - 65535): 101

squareRoot(101) approx. equals 10.0499 (found in 100 iterations).

[instructor@localhost Assign1]$ ./babylonianSqrt Please enter a floating point number (0 - 65535): .25

squareRoot(0.25) approx. equals 0.5 (found in 4 iterations).

image text in transcribed

image text in transcribed

Please submit a C file. Overview: We will program the Babylonian Square Root Method 1. Let number be the number to get the square root of 2. Start with an estimate of 1 3. Recompute estimate -0.5 * (estimate number/estimate) 4. Go back to 3 Stop the looping when either of these is true (estimate*estimate) == number * The number of iterations gets to 100, the maximum 1. Please copy-and-paste the following files (0 Points): babylonianSqrt.c #include #include const int TEXT LEN = 64; void obtainFloat (float* fPtr char text[ TEXT_LEN]; YOUR CODE HERE float squareRoot (float number, int int* numItersPtr max!ters, = 1.0; float estimate I YOUR CODE HERE return (estimate); return (estimate) int main float f; float ans; int numIters obtainFloat (&f); ans squareRoot (f,100,&numIters); printf( "squareRoot(3g) approx. equals %g (found in %d iterations). ", f,ans, numIters return (EXIT SUCCESS); 2. Finish obtainFloat0 (40 Points): It should ask the user to enter a number from 0 to 65535. and lets the user enter a number. If the user enters a number outside that range, it asks again. The number is not returned, but number is placed in the address to which fPtr points 3. Finish squareRooto (60 Points): After setting estimate to 1.0, it should loop and recompute estimate with the expression above. Every time it loops, t should increment the integer to which numItersPtr points. The loop should stop when the condition given above is met Sample Output: [instructorelocalhost Assignl] ./babyloniansqrt Please enter a floating point number (0 65535)-7 Please enter a floating point number (0 65535): 1000000 Please enter a floating point number (0 65535): 9 squareRoot (9) approx. equals 3 (found in 5 iterations) [instructorelocalhost Assignl]$ ./babylonianSqrt Please enter a floating point number (0 65535): 100 squareRoot (100) approx. equals 10 (found in 7 iterations) instructorelocalhost Assign1]$ ./babylonianSqrt Please enter a floating point number (0 - 65535) 101 squareRoot (101) approx. equals 10.0499 (found in 100 iterations) [instructorelocalhost Assignl]$ ./babylonianSqrt Please enter a floating point number (0 65535): .25 squareRoot (0.25) approx. equals 0.5 (found in 4 iterations)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

7 30 -50 4) 2 4 3 5 5 3 1 1 -2 9 9 Do in netwerk simplex method

Answered: 1 week ago

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago