write a program to search for an element in a given array.
If the array was found then display its position otherwise
display appropriate message in c language

Answer Posted / jamshed

IF WE STORE ELEMENTS IN AN ARRAY :


import java.io.*;
class Search
{
public static void main()throws IOException
{
InputStreamReader isr=new
InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int a[]={5,7,9,11,15,20,30,45,89,97};
int i,n,c=0;
System.out.println("Enter a Number to Search");
n=Integer.parseInt(br.readLine());

for(i=0;i<a.length;i++)
{
if(a[i]==n)
{
c++;
System.out.println("\nThe Number "+n+"
Does Exist");
System.out.println("The Position is
"+(i+1));
}
}
if(c==0)
System.out.println("Search Element Not Found");
}
}

Is This Answer Correct ?    18 Yes 27 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can true be a variable name in c?

756


What are the functions to open and close file in c language?

954


What is the purpose of type declarations?

884


What is the general form of function in c?

797


When should a type cast be used?

771


Explain what are bus errors, memory faults, and core dumps?

1026


What are multibyte characters?

853


code for find determinent of amatrix

1741


What is c mainly used for?

824


Tell me when is a void pointer used?

863


What is #line?

822


What is a null pointer in c?

840


Which is best linux os?

769


Is python a c language?

779


Why cant I open a file by its explicit path?

810