need help someone!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: need help someone!

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    need help someone!

    A common requirement is for a program to look for a given piece of data in an array by examining each position in the array in turn. This is known as a linear search. Write a program which reads and stores in an array 10 integers from the command line, and then prompts the user to enter a single integer from standard input. If the entered number occurs in the array, the program should print out the first index at which it occurs:
    > ./a.out 4 39 5 3 0 34 9 99 66 44
    Enter number: 39
    Found at position 1

    If the entered number does not appear in the array the program should print out the message "Not found":
    > ./a.out 4 39 5 3 0 34 9 99 66 44
    Enter number: 42
    Not found



    i have to write a program for that but i am stuck! can someone help and send it to my email or post it!

    emir_abushala@hotmail.com


    thanks

  2. #2
    Join Date
    Oct 2007
    Posts
    369
    Where are you stuck?

    You declare main as so:
    int main(int argc, char**argv)

    and use the char* array (argv) to create a list of numbers on the command line.

  3. #3
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    just loop from 0 to TheNumbersCount .. and compare with the given number if it equals any number inside the loop, break with found at position TheLoopIndex otherwise if it exit the loop without finding anything print Not Found ... try to do it yourself and if you get any problem ask here again ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  4. #4
    Join Date
    Nov 2007
    Posts
    1
    :cool: i wrote that as u said but i dont have the program with me now! cant access it till monday.. but somethin i did wrong and am gettin real frustrated.. if any of u is kind enough and bored to write me the complete program please so i can at least compare wat i did wrong? i will put on the program i wrote as soon as i get it from my office.. monday most probably..
    cheers

  5. #5
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Quote Originally Posted by ea89
    :cool: i wrote that as u said but i dont have the program with me now! cant access it till monday.. but somethin i did wrong and am gettin real frustrated.. if any of u is kind enough and bored to write me the complete program please so i can at least compare wat i did wrong? i will put on the program i wrote as soon as i get it from my office.. monday most probably..
    cheers
    No one will write the program for you champ..

    Show some effort and you will get plenty of help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center