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 / poorni
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,temp=0,n,pos=0,element;
//clrscr();
printf("Search an Element in Array\n");
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value for elements: ");
scanf("%d",&a[i]);
}
printf("Enter the searching element: ");
scanf("%d",&element);
for(i=0;i<n;i++)
{
if(a[i]==element)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position=%
d",element,pos);
else
printf("Element not found\n");
getch();
}
| Is This Answer Correct ? | 56 Yes | 31 No |
Post New Answer View All Answers
What is the difference between scanf and fscanf?
What are the types of bitwise operator?
When we use void main and int main?
Where is c used?
Does c have function or method?
What is structure pointer in c?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
What are the advantages of using macro in c language?
What does c mean?
What is data type long in c?
Where static variables are stored in c?
How pointer is different from array?
What does != Mean in c?
When should a type cast be used?
What is string length in c?