Storing random number in array(sequential search & bubble sort)

This is a discussion on Storing random number in array(sequential search & bubble sort) within the C++ Programming forums, part of the General Programming Boards category; i have generate random number, 1 - 20, such a sequence may or may not contain duplicates. Print each number ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    4

    Storing random number in array(sequential search & bubble sort)

    i have generate random number, 1 - 20, such a sequence may or may not contain duplicates. Print each number as it is generated, and store it in an array, but only if it is not a duplicate of a number already stored.
    Code:
    for(int i=0;i<20;++i) {
        randomInt=rand()%20+1;
        cout<<randomInt<<endl;  // print each number
            
        MyRand[i]=randomInt;  //how to store all unique number(no duplicates in a one-dimensial array (use sequential search) - Use a function to search the existing array 		  
            }
    
      // After you have created the array, print it along with its actual size - Use a function to print the array.
    
    // Then print the array again, this time in sorted in increasing order - Use a function to sort the array (use bubble sort)
    Please can anyone guide me into successfull coding. I need this ASAP, coz the due date is near. Please help, i am beginner , i am trying to learn. E-mail me at: joeraj7@yahoo.com

    Anyone can help, please give me your MSN. ok. THX alot.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Word of advice: we dont like blatently helping people with homework. We'll give you hints, but we wont do the work for you.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    4

    Help

    I could not do the part of storing the unique number in arrays (using sequential search). I really cannot understand that part, can anyone help me to code that part, and i will continue from there and finish my work on my own.

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Start by reading a tutorial or a sorting algorithm?

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    4

    help needed

    I cannot understand sequential search.

    How do i store the unique random numbers (without duplicate), compare the first element with every element and store it, and if the element is equals to any of it, dont store it, but how to do that, any clue, please help?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,935
    I cannot understand sequential search.
    Ever tried flipping through a pile of notes page by page to find the page you want?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Psuedo random numbers in a bubble sort.
    By Sir Andus in forum C++ Programming
    Replies: 10
    Last Post: 04-09-2007, 08:25 PM
  3. non repeating random number generation?
    By gencor45 in forum C# Programming
    Replies: 1
    Last Post: 02-08-2005, 04:23 PM
  4. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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