program to search array element


Prev Tutorial Next Tutorial

program to search array element

For search array element you need to compare all array element with that particular elements.

program to search array element

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

void main()
{
int i,a[50],num,size;
clrscr();
printf("Enter size of array: ");
scanf("%d",&size);
printf("Enter any %d element in array: \n",size);
for(i=0; i<size; i++)
{
scanf("%d",&a[i]);
}
printf("Enter number for find their position: ");
scanf("%d",&num);
for(i=0; i<size; i++)
{
if(a[i]==num)
{
printf("\n index of %d is  %d",num,i);
}
}
getch();
}

Output

Enter size of array: 5
Enter any 5 elements in array:
10
50
30
60
20
Enter number for find their position: 60
index of 20 is 3

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements