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 / bishwas bidari
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
int ele,temp=0,pos=0;
clrscr();
printf("enter the array elements\n");
for (i=0; i<5; i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be search\n");
scanf("%d",&ele);
/* searching for the element*/
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
}
| Is This Answer Correct ? | 85 Yes | 52 No |
Post New Answer View All Answers
Which is better between malloc and calloc?
What is the role of this pointer?
explain what is an endless loop?
shorting algorithmS
How many types of errors are there in c language? Explain
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
What is a char in c?
Is c a great language, or what?
What are 'near' and 'far' pointers?
Can you return null in c?
What is typedef?
How to draw the flowchart for structure programs?
List some applications of c programming language?
What are the benefits of c language?