# Thread: Discrete Mathematics - Algorithm output

1. ## Discrete Mathematics - Algorithm output

1. n=15
2. n=24

begin
input n;
while r > or = to 6 do
r = r - 6;
output r;
end

My question is - what can be said about 'n' if the output from this algorithm is 0?

Thanks
Oz

2. Originally Posted by OsbourneOz
1. n=15
2. n=24

begin
input n;
while r > or = to 6 do
r = r - 6;
output r;
end

My question is - what can be said about 'n' if the output from this algorithm is 0?

Thanks
Oz
The algorithm is repeatedly subtracting 6,
hence, if the result is zero, the starting value must be a multiple of 6

as k(6)-k(6)=0 for any k

3. yes, if you imply 24 then the output value will be '0' will this terminate the algorithm?

4. Originally Posted by OsbourneOz
yes, if you imply 24 then the output value will be '0' will this terminate the algorithm?
that's it,

if you are running a little subroutine,
and the program takes 24 as input data,
then the first run through the routine gives r=24-6=18, $r\ge 0$
second run gives r=18-6=12, $r\ge 0$
third run gives r=12-6=6, $r\ge 0$
fourth run gives r=6-6=0 $r\ge 0$
fifth run gives r=0-6=-6 $r\ge 0\$ no longer

whereas, if n=15

16-6=9
9-6=3
3-6=-3

When the algorithm stops, r will be -6 or -3 depending on the
initial value chosen, but only one of these routines generates an r=0.

5. 1. n=15
2. n=24

begin
input n;
while r > or = to 6 do
r = r - 6;
output r;
end
What is the relationship between n and r? Currently, r seems to be an uninitialized variable.