In this code, If I have to find an element ‘7’, it points to the position of array=2,
but how to get the multiple positions, if array has [4,7,7,8,9] then the answer should point the position as array=1 & array=2..
#include<stdio.h>
int main()
{
int i;
int a[5]={4,5,7,8,9};
int ele,temp=0,pos=0;
printf("Enter the element to be search\n");
scanf("%d",&ele);
// searching for the element
for (i=0; i<5; i++)
{
a[i]=a[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");
}
Try this..