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
Can true be a variable name in c?
What are the functions to open and close file in c language?
What is the purpose of type declarations?
What is the general form of function in c?
When should a type cast be used?
Explain what are bus errors, memory faults, and core dumps?
What are multibyte characters?
code for find determinent of amatrix
What is c mainly used for?
Tell me when is a void pointer used?
What is #line?
What is a null pointer in c?
Which is best linux os?
Is python a c language?
Why cant I open a file by its explicit path?