954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Find function

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 :D

biel_andrada
Newbie Poster
3 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

Post some of your code.We could help out then. :D

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

yeah .. this my assignment in the past .. try it .. it work fine .. ;)

#include <iostream.h>
#include <stdlib.h>
main()
{ 
 //
 int array[10]={1,2,3,4,5,6,7,8,9,10};
 int left=0,right=9,middle;
 int number,i;
 bool sw=false;
 //
 cout<<"ARRAY: ";
 for (i=0;i<=9;i++)
 {
  cout<<array[i]<<";";
 } 
 cout<<" \n"<<"Number to find: ";
 cin>>number;
 while (sw == false && left <= right)
 { 
  middle=(left+right)/2; 
  if (number == array[middle]) 
  {
   sw=true;
   cout<<"number found.\n";
  }
  else
  {
   if (number < array[middle]) right=middle-1;
   if (number > array[middle]) left=middle+1;
  }
 }
 if (sw == false) cout<<"number not found.\n";
 system("Pause");
}
meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You