Powered By Blogger

Wednesday, January 19, 2011

C.S - 11

C - 1 (H.W)


class linear_search
{
public static void main (String args [])
{

int a [] = { 8, 19, 61, 37,24,13, 9, 10 }
int i, f=0, pos = 0, s=13;

for (i=0; i<8, i++)

 {
if ( a[i]==s)
  {
    f=1;
    pos = i+1;
  }
 }

if (f>0)
 {
  System.out.println ("The element is found at position " + pos);
 }
else
 {
  System.out.println (" Element is not present in given list.");
 }

}
}