Sequential Search Algorithm in C

Write a program in c to implement a sequential search algorithm. The technique of identifying a certain value position in a list of values is known as searching. It determines whether or not a search key exists in the data. It’s the mathematical technique of locating a certain object inside a set of items. It can be performed on both internal and external data structures.

#include <stdio.h>
int main()
{
int arr[50], search, cnt, num;
printf("Enter the numbers\n");
scanf("%d",&num);
printf("Enter %d integer(s)\n", num);
for (cnt = 0; cnt < num; cnt++)
scanf("%d", &arr[cnt]);
printf("Enter the number to search\n");
scanf("%d", &search);
for (cnt = 0; cnt < num; cnt++)
{
if (arr[cnt] == search)
{
printf("%d is present at location %d.\n",search,cnt+1);
break;
}
}
if (cnt == num)
printf("%d is not present in array.\n",search);
return 0;
}

 

Output:

Enter the numbers
3
Enter 3 integer(s)
34
56
78
Enter the number to search
34
34 is present at location 1.