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

Answers were Sorted based on User's Feedback



write a program to search for an element in a given array. If the array was found then display its ..

Answer / 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

write a program to search for an element in a given array. If the array was found then display its ..

Answer / sharan

#include<stdio.h>
#include<conio.h>

void main()
{
int a[5],i;
int ele,temp=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

// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
printf("Element found %d , position=%d\n",ele,i);
}
}
if (!temp)
printf("Element not found\n");
} // end of main()

Is This Answer Correct ?    149 Yes 97 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / 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

write a program to search for an element in a given array. If the array was found then display its ..

Answer / 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

write a program to search for an element in a given array. If the array was found then display its ..

Answer / kapil hansrajani

include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,n;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to search : ");
scanf("%d",&j);
for(i=0;i<n;i++)
{
if(a[i]==j)
{
printf("The position of the element %d is %d ",j,i);
break;
}
}
getch();
}

Is This Answer Correct ?    48 Yes 26 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / kirlosky

why should we mention temp=something ..... wat is temp here
plz explain

Is This Answer Correct ?    70 Yes 49 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / sunil makwana

#include<stdio.h>
#include<conio.h>
void searchval(int a[5],int n)
{
int i,temp=0,pos=0;

for (i=0; i<5; i++)
{
// printf("value of array:: %d",i);
if (a[i]==n)
{
temp=1;
pos=i;
}
}
if (temp==1)
{

printf("Element found %d , position==%d",n,pos);
}
else
{
printf("Element not found\n");
}




}
void main()
{
int a[5],i,n;
int ele,pos,temp;

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);

searchval(a,ele);
getch();
}

Is This Answer Correct ?    29 Yes 17 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / abdinasir maxamed abdulle

Array that display search using c languege

Is This Answer Correct ?    16 Yes 8 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / mr. x

#include<stdio.h>
#include<conio.h>
void main ()
{
int a[5],b,c,i;
clrscr();
printf("
Enter no. of elements: ");
scanf("%d",&c);
i=0;
while(i<c)
{
scanf("%d",&a[i]);
i++;
}
printf("
Enter the elements to be searched: ");
scanf("%d",&b);
i=0;
while(i<c &b!=a[i])
{
i++;
}
if (i<c)
{
printf("number found");
i++;
}
else
{
printf(" number not found");
}
getch();
}

Is This Answer Correct ?    8 Yes 5 No

write a program to search for an element in a given array. If the array was found then display its ..

Answer / ghost

#include<stdio.h>
#include<conio.h>

void main()
{
int a[100],i,element,temp,pos;

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",&element);

// searching for the element

for (i=0; i<5; i++)
{
if (a[i]==element)
{
temp=1;
pos=++i;
}
}

if (temp==1)
printf("%d Element found at position==%d",element,pos);
else
printf("Element not found\n");
getch();

} // end of main()

Is This Answer Correct ?    13 Yes 12 No

Post New Answer

More C Interview Questions

can i know the source code for reversing a linked list with out using a temporary variable?

6 Answers   Honeywell,


what is pointer ?

10 Answers   Kernex Micro Systems,


Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4 1) Quick Sort 2) Bubble Sort 3) Merge Sort

7 Answers  


Why doesnt that code work?

0 Answers  


in linking some of os executables are linking name some of them

0 Answers   IBM,






struct abc { unsigned int a; char b; float r; }; struct xyz { int u; struct abc tt; }ww; ww = (struct xyz*)malloc(sizeof(struct xyz)); will the memory be allocated for the inner structure also?

1 Answers   Wipro,


How is null defined in c?

0 Answers  


If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..

0 Answers   IBM, Wipro,


what is difference between array and structure?

44 Answers   College School Exams Tests, CTS, Google, HCL, IBM, Motorola, TCS,


What is %d called in c?

0 Answers  


What is period operator in c?

3 Answers   Wipro,


Why is c so popular?

0 Answers  


Categories