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
what value is returned to operating system after program execution?
Write a program to reverse a string.
How do you determine a file’s attributes?
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.
What does the error message "DGROUP exceeds 64K" mean?
What are types of structure?
difference between Low, Middle, High Level languages in c ?
Explain how can you restore a redirected standard stream?
What are qualifiers and modifiers c?
What is a string?
Define circular linked list.
Explain Basic concepts of C language?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is the total generic pointer type?
What are the types of variables in c?