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 / aishwarya rajan
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,a[30];
char item;
cout<<"Enter the number of elements you would like to enter in the array: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the element"<<i+1<<" :";
cin>>a[i];
}
cout<<"Enter the element you are searching for in the array:";
cin>>item;
if(a[i]==item)
cout<<"The item does exist in the array!! it is the "<<i+1<<" element!!";
else
cout<<"The item is not found in the array!!";
getch();
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
what is the difference between class and unio?
Is this program statement valid? INT = 10.50;
Why can't I perform arithmetic on a void* pointer?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
What is the use of pragma in embedded c?
Explain what are reserved words?
What is the difference between new and malloc functions?
What are preprocessor directives in c?
What is the use of putchar function?
Can a pointer be volatile in c?
How many main () function we can have in a project?
#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }
Can math operations be performed on a void pointer?
How many types of arrays are there in c?
What are global variables and how do you declare them?