0% found this document useful (0 votes)
26 views3 pages

Linear Search

Uploaded by

Kukum Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Linear Search

Uploaded by

Kukum Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

#include <stdio.h>

int main()

int n,a[10],sno,flag=0,count=0;

printf("Enter the no of elements of array ");

scanf("%d",&n);

printf("enter the elements of array ");

for(int i=0;i<n;i++)

scanf("%d",&a[i]);

printf("enter the element to search ");

scanf("%d",&sno);

for(int i=0;i<n;i++){

count+=1;

if(a[i]==sno){

flag=1;

break;

if(flag==1){

printf("%d is found\n",sno);

printf("%d is no of steps",count);}

else{

printf("%d is not found\n",sno);

printf("%d is no of steps",count);

}
return 0;

2.

#include <stdio.h>

#include<time.h>

int main()

clock_t start,end;

int n,a[10],sno,flag=0,count=0;

double total=0;

start=clock();

printf("Enter the no of elements of array ");

scanf("%d",&n);

printf("enter the elements of array ");

for(int i=0;i<n;i++)

scanf("%d",&a[i]);

printf("enter the element to search ");

scanf("%d",&sno);

for(int i=0;i<n;i++){

count+=1;
if(a[i]==sno){

flag=1;

break;

end=clock();

total=(double)(end-start)/CLOCKS_PER_SEC;

if(flag==1){

printf("%d is found\n",sno);

printf("%d is no of steps\n",count);}

else{

printf("%d is not found\n",sno);

printf("%d is no of steps\n",count);

printf("total time taken by the cpu:%f",total);

return 0;

You might also like