Search Element In Array-Recursive
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
|
|
|