Function Array Search in C Plus Plus – This is a C Plus Plus programming language program to input size of an array of integer numbers. This program will take item, from the user, to be searched in this array. If it finds the specified element in array, a suitable message of Item found on location like 5 is shown on the screen. Otherwise it will show a message of “Item not fond in this array”.
How this program works?
- First of all the user will enter size n of the array.
- Enter n items in array
- Input the item to be searched.
- Call the function search() with three arguments, array name, size n and item to be searched in array.
- The function search() will display location if item found or a ‘not found’ message.
- This function uses a for loop from 0 to n-1 for traversing he whole array.
- It compares each element of the array with given item to be searched.
- The sample run output of this program is at end of this tutorial.
The Source Code of C++ Program using Function Array Search
Second Version of Program Search Array
Output of Search an Item in Array Program in C++
Enter number of elements in array[Maximum 100]=5 Enter Element Number 1 in Array=4 Enter Element Number 2 in Array=7 Enter Element Number 3 in Array=89 Enter Element Number 4 in Array=34 Enter Element Number 5 in Array=23 Enter a number to search in array=34 34 is present at location 4 in the given array
Enter number of elements in array[Maximum 100]=10 Enter Element Number 1 in Array=1 Enter Element Number 2 in Array=2 Enter Element Number 3 in Array=3 Enter Element Number 4 in Array=4 Enter Element Number 5 in Array=5 Enter Element Number 6 in Array=78 Enter Element Number 7 in Array=90 Enter Element Number 8 in Array=32 Enter Element Number 9 in Array=12 Enter Element Number 10 in Array=45 Enter a number to search in array=100 100 isn't present in the given array. --------------------------------
- C Program Binary Search in Array
- C Program Linear Search in Array
78 total views, 3 views today