Please solve this query for me.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deven Oza
    New Member
    • Oct 2006
    • 53

    Please solve this query for me.

    Hi every one
    can anybody solve this problem for me.

    What initial values of a and c are required such that the final values of a and b are:

    a = 32
    b = 4



    int a,b,c

    a = ?
    b = 0
    c = ?

    for( b=0; a<12; b++ )
    {
    a = (a+a) * c;
    }




    Thank you
    Deven
  • ManjunathRG
    New Member
    • May 2007
    • 5

    #2
    Originally posted by Deven Oza
    Hi every one
    can anybody solve this problem for me.

    What initial values of a and c are required such that the final values of a and b are:

    a = 32
    b = 4



    int a,b,c

    a = ?
    b = 0
    c = ?

    for( b=0; a<12; b++ )
    {
    a = (a+a) * c;
    }




    Thank you
    Deven

    hi devan,
    simple logic says that a= c= 1 . But the condition in your for loop has a a<12 condition. So how can the final value for a be 32..?? If the condition a<12 is ignored then a = c =1 gives a = 32 when b =4. :)

    Comment

    • chandu031
      Recognized Expert New Member
      • Mar 2007
      • 77

      #3
      Originally posted by Deven Oza
      Hi every one
      can anybody solve this problem for me.

      What initial values of a and c are required such that the final values of a and b are:

      a = 32
      b = 4



      int a,b,c

      a = ?
      b = 0
      c = ?

      for( b=0; a<12; b++ )
      {
      a = (a+a) * c;
      }




      Thank you
      Deven
      Hi,

      First of all this is not an Oracle query. But let me answer this for you in good spirit.

      Since the final value of b is 4 , there will be 5 iterations
      Iteration 1 : a = 2ac
      Iteration 2: a = 4 ac^2
      Iteration 3 : a = 16 ac^3
      Iteration 4 : a = 256 ac^4
      Iteration 5 : a = 65536 ac^5

      Now assuming that this will be the exit condition you have two equations and two unknowns now:

      65536 ac^5 = 32
      256 ac^4 < 12

      Lets put this in this form:

      ac^5 = 1/2048
      ac^4 < 3/64

      These two equations will give you infinite number of solutions. You can choose any of those answers. For example a = 1/64 and c = 1/2 is one answer and also a = 1/2 and c = 1/4 is another solution..

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        This question is being moved to Miscellaneous as no language is specified.

        ADMIN

        Comment

        • acfuchs
          New Member
          • May 2007
          • 1

          #5
          Hi!

          You can use this start values:
          a = 0.125
          c = 2

          Anton

          Comment

          • jaiminpsoni
            New Member
            • Sep 2007
            • 2

            #6
            The answer is
            a = 2
            c = -1

            Comment

            Working...