Thread: please help (sequential search)

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    12

    please help (sequential search)

    Ive brought an array into this function of 100 indexes. I need a way to search each cell with a random number "randx"into the array, and count the number of successful searches. Nos is number of searches. Plaese help me out here, ive been working on this for a while, and im stuck.

    Code:
    #include "my.h"
    
    void searchNum(int Ar[ ], int* sch, int* suc, float* percent, float* tps, int lo, int range, int nos)
    {
    int randx;
    int i;
    
    for(i=0;i<nos;i++)
    {
                    randx=(((rand())%range)+lo);
    //I DONT KNOW WHAT TO PUT HERE
    
    }                       
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    12
    This is what i have

    Code:
    for(i=0;i<nos;i++)
    {
            randx=(((rand())%range)+lo);
            count=0;
            for(j=0;j<100;j++)
            { 
                    count++;
    
    
                            if(Ar[j]==randx)
                    {       *suc++;
    
                    }
            }
            
            
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > *suc++;
    Increments the pointer

    (*suc)++;
    Increments what the pointer points to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Recursive sequential search
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2002, 11:06 AM