Beginner square root question

Discussion in 'Java' started by Stefan Ram, Jul 8, 2008.

  1. Stefan Ram

    Stefan Ram Guest

    Ray Leon <> writes:
    >I have the following algorithm
    >I would appreciate someone to check if this is mostly correct.


    To check whether it is correct, one needs to
    compare its actual behavior with the specification
    for its required behavior.

    Without a specification, it is »not even wrong«.

    Also, this is a Java newsgroup, but your post does
    not refer to Java.
     
    Stefan Ram, Jul 8, 2008
    #1
    1. Advertising

  2. Stefan Ram

    Ray Leon Guest

    I have the following algorithm

    Algorithm

    Sqrt

    1. Input: a real number X
    If (X < 0) Then
    Display: X ³ cannot be negative.²
    STOP
    Else
    sqrt(X) = X^0.5
    Print ³The square root of X is² sqrt(X)

    2. Exit

    My flowchart is on the following web page:
    http://www.popeyeray.com/lesson6.htm

    I would appreciate someone to check if this is mostly correct.
    I also am not sure about the error message and how to put it into my
    flowchart.

    Thank you
    Ray
     
    Ray Leon, Jul 8, 2008
    #2
    1. Advertising

  3. Stefan Ram

    Mark Space Guest

    Stefan Ram wrote:

    > To check whether it is correct, one needs to
    > compare its actual behavior with the specification
    > for its required behavior.


    To the OP:

    To expand on this a bit, what is your algorithm supposed to do when X is
    negative? Obviously, you display "X cannot be negative" and stop, but
    was that the required behavior? What if in the case of negative number
    input the algorithm was really supposed to make X positive, take the
    square root, then display "Ri" to signify an imaginary number? (R =
    square root.)

    So, your algorithm is probably correct, but you do need to get the idea
    down of a specification. Please make sure to tell us first what the
    algorithm is supposed to do, then give us an implementation to check.

    It's like those problems in geometry where you're "Given X, Y, Z, show
    that A is true." Then show the work. You've just shown us the work, we
    aren't sure what you were given to do.

    And it would be nice if you included Java in there somehow.
     
    Mark Space, Jul 8, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luca
    Replies:
    1
    Views:
    1,042
    salman sheikh
    Apr 29, 2004
  2. Replies:
    0
    Views:
    1,241
  3. Christian

    Fix point square root

    Christian, Apr 25, 2005, in forum: VHDL
    Replies:
    5
    Views:
    6,667
    jeppe
    Mar 18, 2010
  4. Jeremy Watts

    'big square root' for BigDecimal

    Jeremy Watts, May 26, 2005, in forum: Java
    Replies:
    4
    Views:
    3,572
    Boudewijn Dijkstra
    May 26, 2005
  5. David Harmon
    Replies:
    2
    Views:
    2,914
    cplusplus
    Jun 14, 2006
Loading...

Share This Page