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
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
How would you obtain the current time and difference between two times?
State two uses of pointers in C?
what is the structure pointer?
Explain what is the general form of a c program?
What do you understand by normalization of pointers?
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
what are the advantages of a macro over a function?
a program that can input number of records and can view it again the record
How reliable are floating-point comparisons?
Which is an example of a structural homology?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
What is the role of && operator in a program code?
Place the #include statement must be written in the program?