Results 1 to 4 of 4

Thread: I had a question in c++

  1. #1
    Join Date
    Mar 2011
    Posts
    3

    I had a question in c++

    hi .
    i have two questions in my book .
    that i can't understand them


    The mode of an array of numbers is the number m in the array that is repeated most frequently. If more than one number is repeated with equal maximal frequencies, there is no mode. Write a program that accepts an array of numbers and returns the mode or an indication that the mode does not exist

    who can write this code .
    my idea is i should be their two function the first is to sort the array aompare the elements .
    and other function is to chick if there mode or not
    if any one can explain ..
    because i did't study the sorting until now .


    2
    the median of an array of numbers is the element m of the array such that half the remaining numbers in the array are greater than or equal to m and half are less than or equal to m . if the numbers of elements in the array is odd . if the number of elements is even .the median is the average of the two elements m1 and m2 , such that half the remaining elements are greater than or equal to m1,m2 and half the elements are less than or equal to m1,m2 . write a c function that accepts an array of numbers and return the median of the numbers in the array

    what the mean of median ?



    ....
    also
    plz if you have any goog refrence to learn programming
    that can help me .


    thanks alot

    ...
    Last edited by it-girl; 17-03-2011 at 11:54 PM.

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: question in c++ ..

    Why cant you just create a 2-dimensional array in function mode(), that contains the value in the original array and the count of the number of times it appears in the original array.

    Code:
    int mode (int arr[MAX])
    {
    int totals[2][MAX] = {0};
    int i, nItemsAdded = 0;
    for(i = 0; i < MAX; i++)
    {
       // search totals to see if the value is already there.  If not, then
       // add it.  If its already in totals array then just increment
       // the counter for it.
       int j;
       int found = 0;
       for(j = 0; found == 0 && j < nItemsAdded; ++j)
       {
            if( totals[0][j] == arr[j])
            {
               found = 1; // set flag indicating value found
               ++totals[1][j]; // bump count
             }
        }
        if( found == 0)
        {
           totals[0][nItemsAdded] = arr[i];
           totals[1][nItemsAdded] = 1;
           ++nItemsAdded;
         }
    }

  3. #3
    Join Date
    Mar 2011
    Posts
    3

    Re: question in c++ ..

    no if we just use two function its easer for me to undestand .
    and its have less running time ..

    thanks .

  4. #4
    Join Date
    Mar 2011
    Posts
    3

    Re: I had a question in c++

    .... : ( ...

Similar Threads

  1. Replies: 8
    Last Post: 27-01-2012, 01:14 PM
  2. PCI-E 2.0 Question
    By fochdion in forum Monitor & Video Cards
    Replies: 1
    Last Post: 26-08-2010, 08:59 PM
  3. VB.net question
    By Daren in forum Software Development
    Replies: 4
    Last Post: 12-03-2009, 05:40 PM
  4. .pst question
    By bac15 in forum Windows Software
    Replies: 2
    Last Post: 03-03-2009, 07:09 PM
  5. USB 3 Question
    By bigboy in forum Hardware Peripherals
    Replies: 3
    Last Post: 16-12-2008, 08:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,861,826.69302 seconds with 18 queries