Results 1 to 3 of 3

Math Help - Algorithms

  1. #1
    Junior Member
    Joined
    Nov 2009
    Posts
    28

    Algorithms

    Use the following pseudo code with your own choice of values of X.

    10 INPUT X
    20 LET Y = X/3
    30 LET R = Y - INT(Y)
    40 IF R = 0 PRINT ACCEPT, GOTO A
    50 PRINT REJECT
    60 LABEL A
    70 END

    (i) Explain what is being achieved.


    What I did is...
    X Y R INT(Y) A
    10 3
    20 1
    30 0
    40
    50
    60
    70

    I don't really get how to do it :S

    (ii)If you replaced the line LET Y = X/3 by the line LET Y = x/5, how would this change the outcome of the above?
    ->?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Oct 2010
    Posts
    3
    The pseudo code checks if x is divisible by three, prints accept if it is, reject if not. if your replace line 20 with LET Y = x/5 it checks if x is divisible by 5 instead.
    example x = 6
    10 x = 6
    20 y = 2 #6/3
    30 r = 0 #2 - 2
    40 print accept goto 60 #label a
    50 skipped
    60
    70 end


    example 7
    10 x =7
    20 y = 2.333 #7/3
    30 r = .333 # 2.3333 -2
    40 IF statement false do nothing
    50 print reject
    60
    70 end
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by ansonbound View Post
    Use the following pseudo code with your own choice of values of X.

    10 INPUT X
    20 LET Y = X/3
    30 LET R = Y - INT(Y)
    40 IF R = 0 PRINT ACCEPT, GOTO A
    50 PRINT REJECT
    60 LABEL A
    70 END

    (i) Explain what is being achieved.


    What I did is...
    Code:
          X   Y   R   INT(Y)   A
    10   3
    20        1
    30             0
    40
    50
    60
    70
    I don't really get how to do it :S

    (ii)If you replaced the line LET Y = X/3 by the line LET Y = x/5, how would this change the outcome of the above?
    ->?
    1. A is a label not a variable so should not appear in the trace table.

    2. Observe that R is the fractional part of Y

    3. observe that Y is X/3

    Hence R==0 if and only if X is divisible by 3.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Algorithms
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: October 8th 2010, 09:48 PM
  2. algorithms
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: March 16th 2010, 02:25 PM
  3. Algorithms
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: December 17th 2009, 07:11 AM
  4. Algorithms
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: December 4th 2009, 03:06 AM
  5. Algorithms
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: March 4th 2009, 11:33 AM

Search Tags


/mathhelpforum @mathhelpforum