Search Array Elements Program in C++


Prev Tutorial Next Tutorial

Search an Array Elements Program in C++

For search array element you need to compare all array element with that particular elements. In below C++ program we have to search an element in a given array using linear search algorithm. If given element is present in array then we will print it's index otherwise print a message saying element not found in array.

To understand this code you need basic knowledge about Array in C++ and For Loop in C++.

Linear Search in C++

In linear search algorithm, we compare targeted element with each element of the array. If the element is found then its position is displayed. The worst case time complexity for linear search is O(n).


Input Array : [6, 12, 9, 8, 31, 10, 25]
Element to search : 31
Output : 
Element found at index 4

Search Array Elements Program in C


void main()
int i,a[50],num,size;
cout<<"Enter size of array: ";
cout<<"Enter any"<<size <<"element in array: \n";
for(i=0; i<size; i++)
cout<<"Enter number for find their position: ";
for(i=0; i<size; i++)
cout<<"\n index of "<<num <<" is " <<i;


Enter size of array: 5
Enter any 5 elements in array:
Enter number for find their position: 50
index of 50 is 3

Note: Here we print number inxed value. That's why actual position of number is less than 1.

search array element program in c++
Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499. Contact no. 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: or 9999595223 Try this Keyword C++ Programs