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
p*=(++q)++*--p when p=q=1 while(q<=6)
What is the hardest programming language?
What are dangling pointers in c?
Write a program to print ASCII code for a given digit.
What is wild pointer in c?
Is python a c language?
Why do we need arrays in c?
Can you tell me how to check whether a linked list is circular?
Ow can I insert or delete a line (or record) in the middle of a file?
GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)
please give me some tips for the placement in the TCS.
What is the best style for code layout in c?
Write a code to generate divisors of an integer?
Subtract Two Number Without Using Subtraction Operator
What is omp_num_threads?