how to develop a algorithm for mean value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ballpen1019
    New Member
    • Mar 2010
    • 7

    how to develop a algorithm for mean value

    I am facing a problem on how to develop a algorithm for mean value.
    Since the numbers are entered by the user, in other word,the user can enter the number as their wish. Beside that, i also need to find the maximum value from the numbers that entered by the user
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    What sort of mean value? geometrical, arithmetical, harmonic...?
    loop until n=-99
    { get an integer
    if(=-99)break
    prod *=integer
    count++
    }
    the geom_mean=pow(p rod,1/count)......... .i think!
    assuming geom_mean, prod and count are double types.

    Comment

    • ballpen1019
      New Member
      • Mar 2010
      • 7

      #3
      actually the mean value is the average value for a series of numbers that entered by the user..
      the problems are
      1) i need to calculate the average value from the numbers that enter by the user and the user can enter any numbers as their wish...in other word, i do not know how many numbers that the user will enter into the program.
      2) average value=(x1+x2+.. .....Xn)/n, how can i transform this equation into machine language that allow the user to enter the value as they wish and calculate the average value in C programming.

      so..i hope someone can answer my question as soon as possible.
      Thank u

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        There are two basic strategies:
        1. Acquire all of the inputs from the user and then perform your calculations.
        2. Fold each user input into intermediate calculations as soon as it is entered.

        In the first case you need a place to put all those input values -- either a static array sized for the maximum allowable number of inputs or dynamic storage that grows as more values are entered.

        In the second case you need to verify that your particular calculation can be accomplished in this as-you-go manner. Not all calculations can be done this way.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          how to develop a algorithm for mean value..
          As you are aware an algorithm is not C or C++ code, it is an expression of the logic to be followed to achieve the desired result.
          for example the following is an algorithm to convert from decimal to binary.
          1. assert x>0.
          2. set k=0.// k is a subscript
          3. if x is odd, set b[k]=1. otherwise set b{k]=0.
          4.subtract b[k] from x.
          5. divide x by 2.
          6 add 1 to k.
          7. if x>0 repeat steps 3-6.
          8. return b[k]......b[2]b[1]b[0].
          so in your case........to be practical you have to limit the number of integers input.
          1. enter an integer.
          2. keep count of number or integers input
          3. maintain a running total.
          4. repeat 1-2 until Ctrl+Z is pressed (this completes input and gives count a final value).
          5. Calculate mean (running total / count).
          6. print mean.
          Was this the sort of thing you were looking for?

          Comment

          • ballpen1019
            New Member
            • Mar 2010
            • 7

            #6
            thank you so much...mr whodgson and donbock.....

            Comment

            Working...