Thursday, 5 July 2012

Program to identify enter number is available or not within array of elements using c++.

#include<iostream>
using namespace std;

int main()
{
int n,flag,j,k;

    cout<<"Enter your total number here";
    cin>>n;
    int a[n];
        for(j=0;j<n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :";
        cin>>a[j];
        cout<<endl;
        }

    flag=0;
    cout<<endl<<"Array input over";
    cout<<endl<<"Enter your number";
    cin>>k;
        for(j=0;j<n;j++)
        {
        if (k==a[j])
        {
        flag=1;
        cout<<"your number is at the position :"<<j+1<<endl;
        }           
        }
        if(flag==0)
        cout<<"enter number is not available in array";
           
        return 0;
}