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
number of times a digit is present in a number
What is the use of c language in real life?
What is exit() function?
Can we use visual studio for c?
What is use of bit field?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What are the key features in c programming language?
Why main function is special give two reasons?
develop algorithms to add polynomials (i) in one variable
What is the difference between exit() and _exit() function in c?
What is indirection? How many levels of pointers can you have?
What is sizeof int?
a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none
What is wrong in this statement? scanf(ā%dā,whatnumber);
What does c mean?