linearsearch.c
24 linesc
DOWNLOAD
1// Aim: Program to perform Linear Search on an array.
2#include<stdio.h>
3void main(){
4	int a[30],n,s,i,c=0;
5	printf("Enter the limit of the array :");
6	scanf("%d",&n);
7	printf("enter the elements of the array :");
8	for(i=0;i<n;i++){
9		scanf("%d",&a[i]);
10	}
11	printf("Enter the name to be searched :");
12	scanf("%d",&s);
13	for(i=0;i<n;i++){
14		if(a[i]==s){
15			c++;
16			break;
17		}}
18	if(c==0){
19		printf("\nThe number %d is not found",s);}
20	else{
21		printf("\nThe number %d is found at %d position",s,i+1);
22	}
23}
24