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 is the sizeof () a pointer?
What is a program?
Why is c used in embedded systems?
Why isnt any of this standardized in c?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
What are different types of variables in c?
Explain is it valid to address one element beyond the end of an array?
What is static memory allocation?
What are the modifiers available in c programming language?
what are the 10 different models of writing an addition program in C language?
What is pass by reference in c?
Why is it important to memset a variable, immediately after allocating memory to it ?
I came across some code that puts a (void) cast before each call to printf. Why?
What is the use of a ‘ ’ character?
Explain the concept and use of type void.