Tuesday, 27 November 2012

Search an Element and Find The Occurance

using System;
using System.Collections.Generic;
using System.Text;

namespace search_element_find_position
{
class search
{
static void Main(string[] args)
{
int []a=new int[30];
int n,s,i;
Console.WriteLine("SEARCH AN ELEMENT AND FIND THE OCCURANCE");
Console.WriteLine("*****************************************");
Console.WriteLine("\n Enter the no of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the elements one by one");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());

}
Console.WriteLine("The Elements Are");
for (i = 1; i <= n; i++)
{
Console.WriteLine("{0}", a[i]);
}
Console.WriteLine("Enter the Element to Search");
s = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
if (a[i]==s)
{
Console.WriteLine("The Element is in the Set,The Position is{0}",i);
}

}


}
}
}

No comments:

Post a Comment