main()
{
int a[10],i,n,m,c=0,loc=0;
printf("Enter the size of an array");
scanf("%d",&n);
printf("\nEnter the elements of the array");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the element to search");
scanf("%d",&m);
for(i=0;i<=n;i++)
{
if(a[i]==m)
{
c=1;
loc=i+1;
break;
}
}
if(c==0)
printf("\nThe number is not in the list");
else
printf("\nThe number is found at location %d",loc);
}
Output:
Enter the size of an array5
Enter the elements of the array10
20
30
40
50
enter the element to search22
The number is not in the list
Enter the size of an array5
Enter the elements of the array10
20
30
40
50
enter the element to search20
The number is found at location 1
No comments:
Post a Comment