Results 1 to 5 of 5

Math Help - Discrete Mathematics - Algorithm output

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    6

    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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Dec 2009
    Posts
    3,120
    Thanks
    1
    Quote Originally Posted by OsbourneOz View Post
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2010
    Posts
    6
    yes, if you imply 24 then the output value will be '0' will this terminate the algorithm?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Dec 2009
    Posts
    3,120
    Thanks
    1
    Quote Originally Posted by OsbourneOz View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,418
    Thanks
    718
    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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. discrete mathematics
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: October 1st 2010, 05:39 PM
  2. What is discrete Mathematics About ?
    Posted in the Discrete Math Forum
    Replies: 7
    Last Post: June 4th 2009, 09:28 PM
  3. Mathematics: Discrete-Mathematics (Algorithems)
    Posted in the Discrete Math Forum
    Replies: 3
    Last Post: November 2nd 2008, 06:27 AM
  4. discrete mathematics..help!!!!!
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: September 12th 2008, 04:43 AM
  5. An algorithm problem Discrete Mathematics class
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: August 26th 2008, 04:34 PM

Search Tags


/mathhelpforum @mathhelpforum