using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i,n,num,flag=0;
int[] a = new int[10];
Console.Write("Enter the number of elements: ");
n=int.Parse(Console.ReadLine());
Console.Write("Enter the elements");
for(i=1;i<=n;i++)
{
a[i]=int.Parse(Console.ReadLine());
}
Console.Write("Enter the element to be searched: ");
num = int.Parse(Console.ReadLine());
for (i = 1; i <=n; i++)
{
if (a[i] == num)
{
flag++;
break;
}
}
if (flag == 1)
Console.Write("The element is found at position: " + i);
else
Console.Write("The element is not found");
Console.ReadKey();
}
}
}
/*Do leave a comment if you find this useful*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i,n,num,flag=0;
int[] a = new int[10];
Console.Write("Enter the number of elements: ");
n=int.Parse(Console.ReadLine());
Console.Write("Enter the elements");
for(i=1;i<=n;i++)
{
a[i]=int.Parse(Console.ReadLine());
}
Console.Write("Enter the element to be searched: ");
num = int.Parse(Console.ReadLine());
for (i = 1; i <=n; i++)
{
if (a[i] == num)
{
flag++;
break;
}
}
if (flag == 1)
Console.Write("The element is found at position: " + i);
else
Console.Write("The element is not found");
Console.ReadKey();
}
}
}
/*Do leave a comment if you find this useful*/
No comments:
Post a Comment