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;


Recommended Answers

All 5 Replies

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 found the mode!!!

I need help with random number:

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

Here are one of the output


as you can see the number are same almost

what do you expect? Your pogram is generating 30 random numbers that are between 1 and 30.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.