Write an algorithm to display this repeated calculation, Data Structure & Algorithms

The following formula is used to calculate n: n = x * x/(1 - x) . Value x = 0 is used to stop algorithm. Calculation is repeated using values of x until value x = 0 is input. There is also a need to check for error conditions. Values of n and x must be output. Write an algorithm to display this repeated calculation using pseudocode.

NOTE: It's much easier in this illustration to input x first and then loop round doing calculation until eventually x = 0. Due to this, it would be essential to input x twice (which implies inside the loop and outside the loop). If input x occurred only once it would result in a more complicated algorithm.  (Also note in algorithm that <> is used to represent ≠).

A while loop is used here, however a repeatloop would work just as well.    

input x

while x <> 0 do

if x = 1 then print "error"

else n = (x * x)/(1 - x)

print n, x

endif

input x

endwhile

 

Posted Date: 9/11/2013 3:57:28 AM | Location : United States







Related Discussions:- Write an algorithm to display this repeated calculation, Assignment Help, Ask Question on Write an algorithm to display this repeated calculation, Get Answer, Expert's Help, Write an algorithm to display this repeated calculation Discussions

Write discussion on Write an algorithm to display this repeated calculation
Your posts are moderated
Related Questions
If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Write a program to simulate searching over a hashed file, with different assumptions for the sizeof file pages.Write a program to perform equality search operations on the hashed f

Methods of Collision Resolution 1)  Collision Resolution by separate chaining  2)  Collision Resolution by open addressing

Binary Search Tree usage: Write a program to compare the time taken for a search in a skewed tree, a balanced tree, and a random tree. Speci cally, your program should do the

the deference between insertion,selection and bubble sort

This algorithm inputs number of hours of sunshine recorded every day for a week (7 days). Output is the highest value for hours of sunshine and average (mean) value for numbers of

Q. Write down an algorithm to insert a node in between any two nodes in a linked list         Ans. Insertion of a the node after the given element of the listis as follows

Merge sort is a sorting algorithm which uses the basic idea of divide and conquers. This algorithm initially divides the array into two halves, sorts them separately and then merge

Which sorting methods would be most suitable for sorting a list which is almost sorted  Bubble Sorting method.

Using the cohen sutherland. Algorithm. Find the visible portion of the line P(40,80) Q(120,30) inside the window is defined as ABCD A(20,20),B(60,20),C(60,40)and D(20,40)