Question: I am doing a project for my c programmng class and I am having major trouble was hoping i could get some help. COP 2220

I am doing a project for my c programmng class and I am having major trouble was hoping i could get some help.

COP 2220 Project 3 - Algorithmic Calculator In this project we will build a simple calculator to calculate the square root of a number and the inverse of a number iteratively. Function 1: Menu The program should contain a menu A. Find the square root of a positive number. B. Find the inverse of a positive number. Q. Quit The menu should be repeatedly called after each calculation until the user enters Q or q. The menu should accept upper and lower case letters. If the us er enters anything other than A, a, B, b, Q or q an error: 'Error. Invalid Selection.' should be given and the user prompted to enter a new choice with the menu. Choice Q or q should exit the program.

Part A. Function 2: Algorithm for the square root of a number

if xb-1 is a guess for the square root of a number N, a closer estimate of the square root can be found by

Xk (xk-1+ N/Xk-1)

Once this new value is found, the result can be improved again by setting xb-1 = xk and repeating the calculation until the result is found.

inputs:

The

user should enter the number N.

If N is not positive an error should be given and the user asked again to enter N.

calculations:

initialze x0 = (N+1)/2

Calculate the square root of N iteratively using Newton's algorithm until

- The algorithm converges [xk * xk - N] < e OR

- The number of iterations of the algorithm is greater than 100.

Output:

If the number of iterations was exceeded, print a message saying so.

If the algorithm converged, print the result and the iteration count at which convergence was achieved as well.

Part B. Function 3: Finding the inverse of a positive number without using division.

if xb-1 is a guess for the inverse of a number N, a closer estimate of the square root can be found by

xk = xk-1(2-Nxk-1)

Once this new value is found, the result can be improved again by setting xb-1=xk and repeating the calculation until the result is found.

inputs:

The user should enter the number N

If N is not positive an error should be given and the user asked again to enter N.

The user should enter an initial guess of x0

if x0 is not positive an error should be given and the user asked again to enter x0

Calculations:

if (2-Nx0) is not positive, reduce x0/2 until (2-Nx2)>0 is true.

Calculate the inverse of N iteratively using the method above until

- the algorithm converges [Nxk -1] < e OR

- the number of iterations of the algorithm is greater than 100.

output:

f the number of iterations was exceeded, print a message saying so.

If the algorithm converged, print the result and the iteration count at which convergence was achieved as

well.

Notes:

Assume the user will only enter numerical data whennumerical data is requested.

Use variables of typedouble

Define e as a constant:double EPS = 1.0E-6

Make your program output match the solution file EXACTLY

ALL PROGRAMMING MUST BE IN THE C LANGUAGE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!