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
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
Who is the main contributor in designing the c language after dennis ritchie?
What is 1d array in c?
What are the advantages of using linked list for tree construction?
Can you define which header file to include at compile time?
What does c mean in standard form?
What is the difference between char array and char pointer?
I have seen function declarations that look like this
What does emoji p mean?
difference between native and cross compilers
What is the importance of c in your views?
What is the meaning of && in c?
What is the difference between āgā and āgā in C?
What is the difference between scanf and fscanf?
How can I recover the file name given an open stream?