/*C Program Linear Search*/ #include<stdio.h> #include<conio.h> #include<process.h> void main() { int i,n,ele,a[20]; printf("enter number of elements:\n"); scanf("%d",&n); printf("enter %d elements\n",n); for(i=0; i<=n-1; i++) scanf("%d",&a[i]); printf("enter the element to be searched:\n"); scanf("%d",&ele); for(i=0; i<=n-1; i++) { if(a[i]==ele) { printf("element found at %d position",i+1); exit(0); } } printf("element %d not found",ele); }
enter number of elements: 9 enter 9 elements 45 65 9 78 15 24 35 67 123 enter the element to be searched: 78 element found at 4 position
No comments:
Post a Comment