2017-10-13 23:16:21 -03:00
|
|
|
#include <stdio.h>
|
2017-10-13 23:08:58 -03:00
|
|
|
|
2020-04-08 09:41:12 -04:00
|
|
|
int linearsearch(int *arr, int size, int val)
|
|
|
|
{
|
2017-10-13 23:08:58 -03:00
|
|
|
int i;
|
2020-04-08 09:41:12 -04:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
2017-10-13 23:08:58 -03:00
|
|
|
if (arr[i] == val)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-08 09:41:12 -04:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int n, i, v;
|
2017-10-13 23:08:58 -03:00
|
|
|
printf("Enter the size of the array:\n");
|
2020-04-08 09:41:12 -04:00
|
|
|
scanf("%d", &n); //Taking input for the size of Array
|
2017-10-13 23:08:58 -03:00
|
|
|
|
2019-10-02 09:11:55 +05:30
|
|
|
int a[n];
|
2019-10-03 09:04:29 +05:30
|
|
|
printf("Enter the contents for an array of size %d:\n", n);
|
2020-04-08 09:41:12 -04:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
scanf("%d", &a[i]); // accepts the values of array elements until the loop terminates//
|
2017-10-13 23:08:58 -03:00
|
|
|
|
|
|
|
printf("Enter the value to be searched:\n");
|
2019-10-02 09:11:55 +05:30
|
|
|
scanf("%d", &v); //Taking input the value to be searched
|
2020-04-08 09:41:12 -04:00
|
|
|
if (linearsearch(a, n, v))
|
2017-10-13 23:16:21 -03:00
|
|
|
printf("Value %d is in the array.\n", v);
|
2017-10-13 23:08:58 -03:00
|
|
|
else
|
2017-10-13 23:16:21 -03:00
|
|
|
printf("Value %d is not in the array.\n", v);
|
2020-04-08 09:41:12 -04:00
|
|
|
return 0;
|
2017-10-13 23:08:58 -03:00
|
|
|
}
|