#include<stdio.h>
#include<conio.h>
main()
{
int a[20],i,key,n;
clrscr();
printf("Enter the number of elements in the array\t");
scanf("%d",&n);
printf("Enter the elements of the array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to be searched\t");
scanf("%d",&key);
for(i=0;i<=n;i++)
{
if (a[i]==key)
{
printf("The element %d occurs at location %d of the array\n",key,i+1);
break;
}
}
if (i>n)
printf("The element %d does not exist in the array\n",key);
getch();
}
/*
OUTPUT
--------
Enter the number of elements in the array 5
Enter the elements of the array
1
2
3
4
5
Enter the element to be searched 1
The element 1 occurs at location 1 of the array
Enter the number of elements in the array 5
Enter the elements of the array
2
3
1
5
7
Enter the element to be searched 8
The element 8 does not exist in the array
*/
#include<conio.h>
main()
{
int a[20],i,key,n;
clrscr();
printf("Enter the number of elements in the array\t");
scanf("%d",&n);
printf("Enter the elements of the array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to be searched\t");
scanf("%d",&key);
for(i=0;i<=n;i++)
{
if (a[i]==key)
{
printf("The element %d occurs at location %d of the array\n",key,i+1);
break;
}
}
if (i>n)
printf("The element %d does not exist in the array\n",key);
getch();
}
/*
OUTPUT
--------
Enter the number of elements in the array 5
Enter the elements of the array
1
2
3
4
5
Enter the element to be searched 1
The element 1 occurs at location 1 of the array
Enter the number of elements in the array 5
Enter the elements of the array
2
3
1
5
7
Enter the element to be searched 8
The element 8 does not exist in the array
*/