Find function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 3
Reputation: biel_andrada is an unknown quantity at this point 
Solved Threads: 0
biel_andrada biel_andrada is offline Offline
Newbie Poster

Find function

 
0
  #1
Jul 26th, 2004
Hi! I need help with the find function! I do not know how to use it in finding numbers.

For instance:
1 1 1 1 2 3 4 4 5 5 6 6 6 7 7 7 7

Using the find function, it will count the number of times a number appears.

1: 4 times
2: 1 time
3: 1 time
4: 2 times
5: 2 times
6: 3 times
7: 4 times

I need help with this, please! Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Find function

 
0
  #2
Jul 26th, 2004
Post some of your code.We could help out then.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Find function

 
0
  #3
Aug 1st, 2004
yeah .. this my assignment in the past .. try it .. it work fine ..
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. main()
  4. {
  5. //
  6. int array[10]={1,2,3,4,5,6,7,8,9,10};
  7. int left=0,right=9,middle;
  8. int number,i;
  9. bool sw=false;
  10. //
  11. cout<<"ARRAY: ";
  12. for (i=0;i<=9;i++)
  13. {
  14. cout<<array[i]<<";";
  15. }
  16. cout<<" \n"<<"Number to find: ";
  17. cin>>number;
  18. while (sw == false && left <= right)
  19. {
  20. middle=(left+right)/2;
  21. if (number == array[middle])
  22. {
  23. sw=true;
  24. cout<<"number found.\n";
  25. }
  26. else
  27. {
  28. if (number < array[middle]) right=middle-1;
  29. if (number > array[middle]) left=middle+1;
  30. }
  31. }
  32. if (sw == false) cout<<"number not found.\n";
  33. system("Pause");
  34. }
Real Eyes Realize Real Lies
My Resume
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC