Steps to Follow Executing Linear Search into Array in C Programming
Creating a program is the first step which is made with a program such as code blocks. It involves the creation of an application under the C category. After the creation of the program, the C program files will have a .c extension to set it apart from the rest.
The next step is preprocessing and compiling. After the program is created, it is assembled with the use of a compiler. The compiler translates it into a machine-readable language. Before the final compilation, the preprocessor executes by to adhere to the commands from its directives keenly.
The linker after that links the codes of the programs to functions which were missing. It additionally connects the system of the object with the libraries.
The fourth stage of developing the program is loading whereby the loader puts the completed application (compiled) into the computer. The program is stored in the memory.
Finally, the computer functions by executing the loaded program. Additionally, a user can use a linear search to search the C programming by array, it identifies the position of a specific number in a set of numbers arranged in array form. If the number is found in the collection, it is located.
/* Linear Search into array search the value in serial way*/
/* here a[100] - storage of array value
f,l,m - first, last, mid position of array
x - search value
i - index variable
flag - determine the value found or not found
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,n,x,flag=0;
clrscr();
printf("enter how many value in array\n");
scanf("%d",&n);
printf("Enter %d value \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Which value to be search ->");
scanf("%d",&x);
/* Linear Search logic */
for(i=0;i<n;i++)
if(x==a[i])
{
flag=1;
break;
}
if(flag==0)
printf("%d value not found\n",x);
else
printf("%d value found at location %d\n",x,i);
getch();
}