using System;
public class Search{
/* Возвращает индекс элемента если найден, -1 - если не найден */
static int SearchElement(int[] mas, int element){
int index = -1;
for (int k = 0; k < mas.Length; k++){
if (mas[k] == element){
index = k;
break;
}
}
return index;
}
static void Main(string[] args)
{
Console.WriteLine("Введите число элементов: ");
int N = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите числа массива: ");
int[] mas = new int[N];
for (int i = 0; i < mas.Length; i++)
{
mas[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Введите элемент для поиска: ");
int element = Convert.ToInt32(Console.ReadLine());
int index = SearchElement(mas, element);
if(index != -1){
Console.WriteLine("Элемент найден под индексом: " + index);
}else{
Console.WriteLine("Элемент не найден ");
}
Console.ReadLine();
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFNlYXJjaHsKCQoJLyog0JLQvtC30LLRgNCw0YnQsNC10YIg0LjQvdC00LXQutGBINGN0LvQtdC80LXQvdGC0LAg0LXRgdC70Lgg0L3QsNC50LTQtdC9LCAtMSAtINC10YHQu9C4INC90LUg0L3QsNC50LTQtdC9ICovCglzdGF0aWMgaW50IFNlYXJjaEVsZW1lbnQoaW50W10gbWFzLCBpbnQgZWxlbWVudCl7CgogICAgICAgIGludCBpbmRleCA9IC0xOwoJCWZvciAoaW50IGsgPSAwOyBrIDwgbWFzLkxlbmd0aDsgaysrKXsKCSAgICAgICAgaWYgKG1hc1trXSA9PSBlbGVtZW50KXsgIAoJICAgICAgICAJaW5kZXggPSBrOwoJICAgICAgICAJYnJlYWs7CgkgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGluZGV4OwogICAgfQoKICAgICAgICAKCSBzdGF0aWMgdm9pZCBNYWluKHN0cmluZ1tdIGFyZ3MpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgi0JLQstC10LTQuNGC0LUg0YfQuNGB0LvQviDRjdC70LXQvNC10L3RgtC+0LI6ICIpOwogICAgICAgICAgICBpbnQgTiA9IENvbnZlcnQuVG9JbnQzMihDb25zb2xlLlJlYWRMaW5lKCkpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgi0JLQstC10LTQuNGC0LUg0YfQuNGB0LvQsCDQvNCw0YHRgdC40LLQsDogIik7CiAgICAgICAgICAgIGludFtdIG1hcyA9IG5ldyBpbnRbTl07CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbWFzLkxlbmd0aDsgaSsrKQogICAgICAgIAl7CiAgICAgICAgICAgICAgICBtYXNbaV0gPSBDb252ZXJ0LlRvSW50MzIoQ29uc29sZS5SZWFkTGluZSgpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoItCS0LLQtdC00LjRgtC1INGN0LvQtdC80LXQvdGCINC00LvRjyDQv9C+0LjRgdC60LA6ICIpOwogICAgICAgICAgICBpbnQgZWxlbWVudCA9IENvbnZlcnQuVG9JbnQzMihDb25zb2xlLlJlYWRMaW5lKCkpOwogICAgICAgICAgICBpbnQgaW5kZXggPSBTZWFyY2hFbGVtZW50KG1hcywgZWxlbWVudCk7CiAgICAgICAgICAgIAogICAgICAgICAgICBpZihpbmRleCAhPSAtMSl7CiAgICAgICAgICAgIAlDb25zb2xlLldyaXRlTGluZSgi0K3Qu9C10LzQtdC90YIg0L3QsNC50LTQtdC9INC/0L7QtCDQuNC90LTQtdC60YHQvtC8OiAiICsgaW5kZXgpOwogICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgCUNvbnNvbGUuV3JpdGVMaW5lKCLQrdC70LXQvNC10L3RgiDQvdC1INC90LDQudC00LXQvSAiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgQ29uc29sZS5SZWFkTGluZSgpOwogICAgICAgIH0KfQ==