How to find the position in array. please help ASAP.

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include<iostream>
using namespace std;
int main()
{
      int n,x,i,a[100],flag=0;

      cout<<"Enter a Number ";
      cin>>n;
     
      cout<<"Enter "<<n<<" numbers";
      for(i=0;i<n;i++)
           cin>>a[i];

       cout<<"Enter a Number to be search ";
       cin>>x;
       for(i=0;i<n;i++)
       {
           if(a[i]==x)
          {
                cout<<"Number "<<x<<" is present in position"<<i+1<<endl;
                flag==1;
          }
      }
      if(flag==0)
      {
          cout<<"Search is unsuccessful"<<endl;
      }
       system("PAUSE");
}


it looks good to me. It is one way to do it. The brace count wasn't correct but it looks like it would work.
Thanks for the help! ;)
Topic archived. No new replies allowed.
Pages: 12