Thread: Help with an Array

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    14

    Help with an Array

    Okay I need help with this problem:

    Write a function that verifies if a given number exists in an array of floats. The function is supposed to return the first position in where the number is encountered. If the given number does not exist, the function returns –1.Then write a program that asks the user to enter an array of floats and calls the function.
    The prototype of the function should be like:
    int Search (floats a[ ] , int n, float number)


    Example:
    Consider the following array of floats

    2.1 1 9 -14 1.3 5.9 9 17
    [0] [1] [2] [3] [4] [5] [6] [7]
    If the number to be searched is 5.4 the function returns –1
    If the number to be searched is 9 the function returns 2


    I am having trouble with the function itself. I don't know how to print the index of the number? I just really need help with that right now. Any help would be appreciated. Thanks

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Forgot about the coding part just yet and try to devise an algorithm for solving this.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Special1zed, please don't start another thread for the same problem and program.

    This has already been answered, in the other thread, and this thread should be closed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM