Results 1 to 4 of 4

Math Help - Algorithm

  1. #1
    Newbie
    Joined
    Nov 2006
    Posts
    15

    Algorithm

    pu
    Last edited by chillerbros17; February 28th 2007 at 02:23 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by chillerbros17 View Post
    Consider the following algorithm.

    Input X
    A:= 0
    B:= 0
    Count:= 1
    While X <>0
    If > A then
    Do
    A:= X
    B:= Count
    End Do
    Input X
    Count :=Count + 1
    End While
    Output A, B

    Suppose the inputted values of x are:
    3, 4, 2, 9, 3, 9, 2, 0, 4, 7, 1 (all values may not be used)

    (a) Trace through the algorithm.

    (b) Given a list of numbers, what will A output and what will B output?
    1). Indentation is very helpful in following pseudo code, you can use [code]..[/code]
    tags to delimit a code block where the indentation will sort of work:

    Code:
    Input X
    A:= 0
    B:= 0
    Count:= 1
    While X <>0
        If > A then
            Do 
                A:= X
                B:= Count
            End Do
        Input X
        Count :=Count + 1
    End While 
    Output A, B
    2). What do you want the "> A" in "If > A then" to mean?

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Nov 2006
    Posts
    15
    X > A
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member
    earboth's Avatar
    Joined
    Jan 2006
    From
    Germany
    Posts
    5,830
    Thanks
    123
    Quote Originally Posted by chillerbros17 View Post
    Consider the following algorithm.

    Input X
    A:= 0
    B:= 0
    Count:= 1
    While X <>0
    If > A then
    Do
    A:= X
    B:= Count
    End Do
    Input X
    Count :=Count + 1
    End While
    Output A, B

    Suppose the inputted values of x are:
    3, 4, 2, 9, 3, 9, 2, 0, 4, 7, 1 (all values may not be used)

    (a) Trace through the algorithm.

    (b) Given a list of numbers, what will A output and what will B output?
    Hi, to (a): Use a trace table. I've used the given list of numbers.
    Code:
         x     A     B     count
         -     0     0       1              start
         3     3     1       2
         4     4     2       3
         2     4     2       3
         9     9     3       4 
         3     9     3       4
         9     9     4       5
         2     9     4       5
         0   → break off of program
    output: A = 9
            B = 4
    EB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. algorithm
    Posted in the Advanced Applied Math Forum
    Replies: 3
    Last Post: January 19th 2010, 02:46 AM
  2. Algorithm
    Posted in the Advanced Math Topics Forum
    Replies: 7
    Last Post: November 22nd 2009, 07:11 AM
  3. algorithm
    Posted in the Math Topics Forum
    Replies: 2
    Last Post: July 16th 2008, 01:29 PM
  4. Algorithm
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: February 27th 2008, 01:02 PM
  5. gcd algorithm
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: December 4th 2007, 11:47 PM

Search Tags


/mathhelpforum @mathhelpforum