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

what value is returned to operating system after program execution?

1856


Write a program to reverse a string.

859


How do you determine a file’s attributes?

829


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3586


What does the error message "DGROUP exceeds 64K" mean?

1000


What are types of structure?

856


difference between Low, Middle, High Level languages in c ?

1872


Explain how can you restore a redirected standard stream?

805


What are qualifiers and modifiers c?

766


What is a string?

895


Define circular linked list.

810


Explain Basic concepts of C language?

845


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

815


What is the total generic pointer type?

939


What are the types of variables in c?

794