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
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
What is the heap in c?
what are the advantages of a macro over a function?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
Is a pointer a kind of array?
Explain union. What are its advantages?
Subtract Two Number Without Using Subtraction Operator
What does s c mean in text?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the difference between the local variable and global variable in c?
What is the equivalent code of the following statement in WHILE LOOP format?
Why is c so popular?
Explain a file operation in C with an example.
What is the use of putchar function?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?