Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Search Element In Array-Recursive

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int []arr={1,2,3,4,5,6,7};
            
            Console.WriteLine(Search(arr,0,7));
        }
        
        public static int Search(int []arr, int index, int element)
        {
            if(index==arr.Length)
                {
                    return -1;
                }
            else
            {
                if(arr[index]==element)
                {
                    return 1;
                }
                else
                    return Search(arr, index+1, element);
            }
            
        }
    }
}
 run  | edit  | history  | help 0