averaging random numbers

This is a discussion on averaging random numbers within the C Programming forums, part of the General Programming Boards category; I know how to find the average of numbers, but how do you find the average of already generated random ...

  1. #1
    Unregistered
    Guest

    Question averaging random numbers

    I know how to find the average of numbers, but how do you find the average of already generated random numbers?

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    What sort of average are you looking for? mean, medium
    and if you know how to find the average of numbers it would be the same for the average of random numbers, unless i missunderstood your question.
    do you have code you can post?
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    #include <stdlib.h>

    #define QUANTITY 10

    void main()
    {
    int i, sum=0;
    double avg;

    for (i = 0 ; i < QUANTITY ++i){
    sum += rand();
    }

    avg = sum / QUANTITY;
    }
    Ivan

  4. #4
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    At the risk of sounding picky.
    you missed a semi colon out of your for loop and sum can only hold a value of up to 32,767 so if rand returns that value on the first loop all other values from rand will be ignored.
    you should use a float or double for sum.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    At the risk of sounding CORRECT, let me say this ONE MORE TIME:

    MAIN DOES NOT RETURN VOID IN C. If you insist on returning void, switch to Java!

    Have a nice day.

    Quzah.

  6. #6
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Dont you get fed up saying that Quzah
    lol
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yeah. They need a permanant message at the top thread in the forum. It's title should be:

    "Any thread with the phrase "void main" will be automaticly deleted."

    Quzah.

  8. #8
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    LOL get Kermi3 on the job now
    All spelling mistakes, syntatical errors and stupid comments are intentional.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. Doubts regarding random numbers generation
    By girish1026 in forum C Programming
    Replies: 9
    Last Post: 12-31-2008, 09:47 PM
  3. random numbers
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 10-24-2008, 01:22 PM
  4. random numbers limit
    By HAssan in forum C Programming
    Replies: 9
    Last Post: 12-06-2005, 06:51 PM
  5. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21