0
4.0kviews
Write a C program search a element in a array.
1 Answer
written 2.6 years ago by | • modified 2.6 years ago |
Program
#include<stdio.h>
#include<conio.h>
#define MAX_SIZE 100
void main()
{
int arr[MAX_SIZE];
int size,i,toSearch,found;
printf("Enter size if array:");
scanf("%d", &size);
printf("Enter elements in array:");
for(i=0;i<size;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter element to search:");
scanf("%d", &toSearch);
found=0;
for(i=0;i<size;i++)
{
if(arr[i]==toSearch)
{
found=1;
break;
}
}
if(found==1)
{
printf("%d is found at position %d", toSearch, i+1);
}
else
{
printf("%d is not found in the array", toSearch);
}
getch();
}