# Math Help - Algorithms

1. ## 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?
->?

2. 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

3. Originally Posted by ansonbound
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