Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

arrays

how would i display two different array with random numbers using these parameters
void displayArray(const int*, int);

and also how would i find the numbers that are equal in both arrays using
int * intersection(const int * const, int, const int* const, int, int &);
if anybody has any ideas that would be very helpful thanks

Comments

  • MeshArtistMeshArtist Member Posts: 37
    : how would i display two different array with random numbers using these parameters
    : void displayArray(const int*, int);
    :
    : and also how would i find the numbers that are equal in both arrays using
    : int * intersection(const int * const, int, const int* const, int, int &);
    : if anybody has any ideas that would be very helpful thanks
    :
    :

    Typically, the first parameter would be a constant pointer to an array of integers. The second parameter is the size of the array. Inside your function, you need to make a 'for loop' and spin through each element printing out one. Here is an example function:

    [code]
    void printArray(const int* array, const int size)
    {
    for(int index = 0; index < size; index++)
    {
    cout << array[index] << endl;
    }
    }
    [/code]

    You simply count through each element printing out its contents.

    For the second problem, it depends on how you want to do it. I am assuming you will take two arrays (possibly of different length) and compare each of their elements and only put the common ones in a new array. This will involve dynamic memory allocation if the arrays are of different sizes. You can do this many different ways. In the big picture, you need to set up a loop that picks an element from one array, compares it to the second array, and if a match is found store it in the third array. One way to approach it would be create an array of booleans the size of the largest array in your set. Then count through one array and set all indexes of the boolean array to true for values that it has. Then spin through the second array. If the corresponding indexes are set to 'true' from the previous run, then you know you have an intersection. Take that value and put it in a newly allocated array. Does that make sense? Let me know if you need further help.
    --------------------------------------------
    Jordan - "MeshArtist"
    "Ever saint has a past and every sinner has a future."
    --------------------------------------------

  • Shawn CarterShawn Carter Member Posts: 0

    _ || http://forcoder.org || free ebooks and video tutorials about | PHP, R, Swift, MATLAB, Visual Basic .NET, Visual Basic, Python, Perl, Ruby, C, Scratch, Java, JavaScript, Objective-C, C#, PL/SQL, C++, Assembly, Delphi, Go Scala, Logo, Hack, Lua, COBOL, ML, SAS, Kotlin, Apex, Erlang, Julia, Dart, Awk, Bash, Scheme, LabVIEW, ABAP, FoxPro, Rust, Prolog, Fortran, Alice, Clojure, F#, Crystal, VBScript, Ada, Lisp, Transact-SQL, D | _

Sign In or Register to comment.