Thread: Average of n numbers

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    Average of n numbers

    Prove that average of n numbers is greater than equal to the lowest number and less than or equal to the greatest number.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Since this smells of homework I'm not gonna do a full proof and/or proper proof.

    Assume you have two numbers A and B which have the average n. So the proof needs to show that

    MIN(A,B) <= n <= MAX(A,B)

    Now with two numbers you have three situations:

    1) A = B
    2) A > B
    3) A < B

    However, we really only need to prove 2 or 3 as it can cover both cases.

    1) If A=B then MIN(A,B) = A and MAX(A,B) = A. n = 2A/2 = A. So A <= A <= A is true
    2) If A>B then MIN(A,B) = B and MAX(A,B) = A. Additionally: A = B + x, where x > 0. So n = (A + B)/2 = (B + x + B) / 2 = (2B + x)/2 = 2B/2 + x/2 = B + x/2. So we are left with: B <= B + x/2 <= A. B <= B + x/2 -> 0 <= x/2 and since x>0 it is true. B+x/2 <= A -> B + x/2 <= B + x -> x/2 <= x and since x>0 it is true.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. 3x syntax errors :S, Help a student finalise an assignment
    By Chickenhawk in forum C Programming
    Replies: 14
    Last Post: 07-27-2006, 05:14 AM
  3. I have a function and I need multiple averages returned
    By tommy69 in forum C++ Programming
    Replies: 20
    Last Post: 04-13-2004, 11:45 AM
  4. Min/Max Numbers
    By mzt in forum C++ Programming
    Replies: 1
    Last Post: 03-05-2004, 07:20 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM