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