Question: Please write C not C++ Rules You can use all course material and man pages, but you should be able to solve the problems below
Please write C not C++


Rules You can use all course material and man pages, but you should be able to solve the problems below without web searches or communicating with other students. In the final exam you will be asked to solve similar problems... Your programs must compile without warning using gcc -g -Wall Wextra -Wconversion -Wsign-conversion -0 ... on our lab machines. If there are compiler warnings or errors, there will be considerable mark deductions Test your programs with different values. For now, the speed of your programs is irrelevant. So don't spend time on optimization Your programs must be well structured. Use ctrl-x t in Emacs or a similar command in your editor of choice to pretty-print them. Marks are assigned to functionality and program appearance In case your program hangs, use ctrl-c to terminate it Download README.txt and fill in the requested information Submit README.txt p1.c p2.c on eClass by the due date You can submit as often as you want. We will only consider the last submission for marking Problem 1: Approximating Vac V In this exercise you will write a program that approximates the square root of a given double x > 0 using binary search - which is the algorithm of choice for looking up telephone numbers in a phone book = - 2 You may recall that (V2)2 = x and V > 0. For instance, V4= 2, V9 = 3, V2 ~1.4142135... To approximate v, we can start with interval [1, x] if x > 1 and (x, 1] if x x, x if x 1 Write C program p1.c that implements above algorithm in function double mysqrt(double x), stopping when the relative error (interval length / midpoint) becomes smaller than 10-15, and returning the last mid-point In main() test mysqrt with a few values and print the results along with the sqrt results using the %.20f format, where sqrt is the math library function for which you need to include math.h, and also use the -Im option when compiling Also, comment your program and format it well
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
