C++ program to check the element in the ARRAY

·

1 min read

#include <iostream>
using namespace std;

void findElement(int*p,int size1,int x1){
    for (int i=0;i<size1;i++){
        if (p[i]==x1){
            cout<<"Voilla!, We found it at index "<<i<<endl;
            return;
        }
    }
    cout<<"Sorry this element is not in the Array"<<endl;
}

int main() {
    int arr[]={1,3,4,5,6,8};
    int x;
    int size=sizeof(arr)/sizeof(int);
    cout<<"Enter the element you want to find in the array:"<<endl;
    cin>>x;
    findElement(arr,size,x);



}