Random Number: Whenever I run it show me an error. Here is an error "implicit conversion loses integer precision 'time_t' (aka 'long') to 'unsigned int'", so i put change to srand( (unsigned int) time(NULL) ); it run but it seem the number is not change at all.

void read_array (int read[] , int size1)
    srand (time(NULL));
    for (int index = 0; index < 30; index ++)
        read[index]= rand() % 30 + 1;
    mode(read, 30);
    print_array(read, 30);


Other one is

I am trying to find the mode but it didnt work! can someone help me out..

This is what i got so far

 for (int index = 0; index < size2; index ++)
        //count[mode[index] - 1]++;
        if (mode[index] == mode[index + 1]) // compare the first to sec array
            cout <<"This is number " << again << endl;

4 Years
Discussion Span
Last Post by Ancient Dragon

The mode is the number that appears the most often in the array. If the array contains {1,2,1,3,4,5,8} the mode is 1 because it appears twice and all others appear only once.

One way to calculate the mode is to use another 2d array, the first dimention contains a value from the original array and the second dimention contains a count of the number of times it appears in the original dimension.

Using the previous example data, the 2d array would contain

1  2
2  1
3  1
4  1
5  1
8  1

Now all you have to do is select the value from the 2d array that has the largest count value.


I need help with random number:

Everytime i run it the number look like doesnt change at all.

Here are one of the output


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.