C plus plus assignment help service

Linear search program in c++ using recursion

Leave a Comment
This program runs linear search recursively in an array c++ code
Compiler used: C++ Codeblocks Compiler Concept used:
  • Recursive function Linear Search
  • if else statement

How Program Works
  • Program takes size of array
  • Input elements in array
  • Passing array, key and size to the recursive function recursiveLinearSearch(int array[],int key, int size)
  • Recursive function calls it self until certain conditions fulfill
  • Function returns 1 if record found in array else returns -1

C++ code:
C++ program linear search program using recursive function

    using namespace std;
    int recursiveLinearSearch(int array[],int key,int size){
      if(size <0){
      return -1;
      else if(array[size]==key){
      return 1;
      return recursiveLinearSearch(array,key,size);

    int main() {
      cout<<"Enter The Size Of Array:   ";
    int size;
    int array[size], key,i;
    // Taking Input In Array
    for(int j=0;j<size;j++){
    cout<<"Enter "<<j<<" Element : ";
    //Your Entered Array Is
    for(int a=0;a<size;a++){
       cout<<"array[ "<<a<<" ]  =  ";
    cout<<"Enter Key To Search  in Array";
    int result;
    cout<<"Key Found in Array  ";
    cout<<"Key NOT Found in Array  ";
       return 0;
Linear search program in c++ using recursion code end

More Programs.
Linear Search in  C++

Find Prime Number in C++

For more learning change the program and examine the output


Post a Comment