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 / anuja kulkarni
#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");
} // end of main()
| Is This Answer Correct ? | 483 Yes | 132 No |
Post New Answer View All Answers
how could explain about job profile
c program for searching a student details among 10 student details
How are portions of a program disabled in demo versions?
Explain heap and queue.
Is boolean a datatype in c?
Explain pointer. What are function pointers in C?
Which of these functions is safer to use : fgets(), gets()? Why?
Explain what is operator promotion?
Difference between Shallow copy and Deep copy?
When should a type cast not be used?
What is structure padding in c?
What is the difference between array and linked list in c?
What does == mean in texting?
What is malloc calloc and realloc in c?
Explain the process of converting a Tree into a Binary Tree.