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

Assignment Help:

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

 


Related Discussions:- Write an algorithm to display this repeated calculation

The two famous methods for traversing, The two famous methods for traversin...

The two famous methods for traversing are:- a) Depth first traversal b) Breadth first

What are the properties of colour, Properties of colour Colour descript...

Properties of colour Colour descriptions and specifications generally include three properties: hue; saturation and brightness. Hue associates a colour with some position in th

Insert function, INSERT FUNCTION /*prototypes of insert & find function...

INSERT FUNCTION /*prototypes of insert & find functions */ list * insert_list(list *); list * find(list *, int); /*definition of  anyinsert function */ list * inser

Time complexity, how to learn about time complexity of a particular algorit...

how to learn about time complexity of a particular algorithm

Array, how to define the size of array

how to define the size of array

Declaring a two dimensional array, Declaring a two dimensional array   A...

Declaring a two dimensional array   A two dimensional array is declared same to the way we declare a one-dimensional array except that we state the number of elements in both di

Define graph, A graph is a mathematical structure giving of a set of vertex...

A graph is a mathematical structure giving of a set of vertexes (v1, v2, v3) and a group of edges (e1, e2, e3). An edge is a set of vertexes. The two vertexes are named the edge en

Define a procedure called make-avl-tree, This question deals with AVL trees...

This question deals with AVL trees. You must use mutable pairs/lists to implement this data structure: (a) Define a procedure called make-avl-tree which makes an AVL tree with o

Adjacency matrix representation of a graph, An adjacency matrix representat...

An adjacency matrix representation of a graph cannot having information of : Parallel edges

Program segment for quick sort, Illustrates the program segment for Quick s...

Illustrates the program segment for Quick sort. It uses recursion. Program 1: Quick Sort Quicksort(A,m,n) int A[ ],m,n { int i, j, k; if m { i=m; j=n+1; k

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd