geometric sequence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HighlightReel44
    New Member
    • Apr 2010
    • 11

    geometric sequence

    How i do write a funtion ((IsGeometric)) with variable number of arguments that takes an integer first argument followed by any number of arguments of type ((double)) and returns ((true)) uf the argument of type ((double)) forms a geometric sequence and ((false)) if they don't

    Need question in 4 days

    Thanks. I woudl really appreciate a response in the next 4 days
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    hmm....well, assuming you are aware of the properties of a geometric sequence
    your isGeometric(int ,double,double. .......double) function has only to determine whether if each term (except the first) increases or reduces by the square of its ratio. For example: a , ar, ar^2, ar^3, ar^4 ..........ar^(n-1) is a geometric sequence where ratio 'r' is being raised by increasing powers. If this is true your function should return 'true' or 1 otherwise 'false' or 0. You could do this by examining the successive powers of r or summing the first ? terms and comparing that value with what it should be using the sum formula.which is a(1-r^n)/1-r (assert r!==1). You would of course need a main () driver function to test the function as well as the appropriate #include <header> files.If you post some code there are plenty of people here to help you get it right.

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      Start with any tutorial function about va_arg. And when examining doubles for equality thing about some precision because they might not be equal because of rounding.

      Comment

      • HighlightReel44
        New Member
        • Apr 2010
        • 11

        #4
        ok i'm still a little confused could u give me an example source code of how it should look

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          Take the first 2 elements,
          Set ratio = element 2 / element 1.

          loop through double array
          if an element * ratio doesn't = the next element, return false.
          end loop

          return true.

          Be careful of rounding, and dividing by zero.

          Comment

          • whodgson
            Contributor
            • Jan 2007
            • 542

            #6
            Couldn`t improve on the above method set out by jkmyoung. It`s time for you to convert this into code.

            Comment

            Working...