Program to search an element in an array also print the occurrence and position of that elements in C-language.
#include<stdio.h>
int main()
{
int i,a[10],n,b,c=0;
printf("Enter the size limit maximum is 10\n");
scanf("%d",&n);
printf("Enter the array element\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be searched\n");
scanf("%d",&b);
for(i=0;i<n;i++)
{
if(b==a[i])
{
c++;
printf("Element found at position %d\n",i+1);
}
}
if(c==0)
{
printf("Element not found");
}
else
{
printf("Element is found %d times",c);
}
}
OUTPUT
Enter the size limit maximum is 10
4
Enter the array element
6
4
6
7
Enter element to be searched
6
Element found at position 1
Element found at position 3
Element is found 2 times
Comments
Post a Comment