0

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

3
Contributors
2
Replies
3
Views
13 Years
Discussion Span
Last Post by meabed
0

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");
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.