using System;
namespace MyCompiler {
class Program {
public static void Main(string[] args) {
// Best Case Time Complexity : O(1) because element can find at first index.
// worst case Time Complexity : O(N).
int[] myArr = {1,4,10,12,19,20};
int target = 34;
string name = "Bharat";
char tar = 'a';
int[,] twodarr = {
{12,10,13},
{19,21,34},
{31,2,3}
};
int[] ans = Search2DArray(twodarr,target);
Console.WriteLine("Index Of Target Value is : "+SearchNumber(myArr,target));
Console.WriteLine("Target Value is : "+SearchTarget(myArr,target));
Console.WriteLine("Minimum Number in array is : "+SearchMaxValue(myArr));
Console.WriteLine(SearchChar(name,tar));
Console.WriteLine("Element found at index: ["+ ans[0] + "," + ans[1]+"]");
Console.WriteLine("Max Item in 2D array is : "+SearchMax2DArray(twodarr));
}
// Find Target Element
static int SearchTarget(int[] arr,int target){
if(arr.Length == 0){
return -1;
}
for(int index=0;index<arr.Length;index++){
if(arr[index]==target){
return arr[index];
}
}
return Int32.MaxValue;
}
//Find Index Of An Array
static int SearchNumber(int[] arr,int target){
if(arr.Length == 0){
return -1;
}
for(int i=0;i<arr.Length;i++){
int element = arr[i];
if(element == target){
return i;
}
}
return -1;
}
//Find Max Value Or Min Value;
static int SearchMaxValue(int[] arr){
if(arr.Length==0){
return -1;
}
int min = arr[0];
for(int i=1;i<arr.Length;i++){
//for min value
if(arr[i]<min){
min = arr[i];
}
}
return min;
}
//find Character in String
static bool SearchChar(string str,char a){
if(str.Length==0){
return false;
}
for(int i=0;i<str.Length;i++){
if(str[i]==a){
return true;
}
}
return false;
}
//Search Value In 2D Array
static int[] Search2DArray(int[,] arr,int target){
if(arr.Length==0){
return new int[] { -1, -1 };
}
for(int row=0;row<arr.GetLength(0);row++){
for(int col = 0;col<arr.GetLength(1);col++){
if(arr[row,col]==target){
return new int[]{row,col};
}
}
}
return new int[] { -1, -1 };
}
//Max Item in 2D Array
static int SearchMax2DArray(int[,] arr){
if(arr.Length==0){
return -1;
}
int max =0;
for(int row=0;row<arr.GetLength(0);row++){
for(int col = 0;col<arr.GetLength(1);col++){
if(arr[row,col] > max){
max = arr[row,col];
}
}
}
return max;
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: