#include#include void accept(int [],int); void display(int [],int); void search(int [],int); void main() { int a[20],n; clrscr(); printf("\n How Many Elements You want To Accept: "); scanf("%d",&n); accept(a,n); printf("\n Entered Element are: "); display(a,n); search(a,n); getch(); } void accept(int a[],int n) { int i; printf("\n Enter %d Elements \n",n); for(i=1;i<=n;i++) { printf("\n Enter Element %d : ",i); scanf("%d",&a[i]); } } void display(int a[],int n) { int i; for(i=1;i<=n;i++) { printf("\t%d",a[i]); } } void search(int a[],int n) { int i,ele,flag=0; printf("\n Enter The Element You Want To Search: "); scanf("%d",&ele); for(i=1;i<=n;i++) { if(ele==a[i]) { flag=1; break; } } if(flag==1) { printf("\n Element Found."); } else { printf("\n Element Not Found."); } } /*OUTPUT How Many Elements You want To Accept: 5 Enter 5 Elements Enter Element 1 : 2 Enter Element 2 : 4 Enter Element 3 : 5 Enter Element 4 : 7 Enter Element 5 : 8 Entered Element are: 2 4 5 7 8 Enter The Element You Want To Search: 2 Element Found. How Many Elements You want To Accept: 4 Enter 4 Elements Enter Element 1 : 22 Enter Element 2 : 11 Enter Element 3 : 77 Enter Element 4 : 33 Entered Element are: 22 11 77 33 Enter The Element You Want To Search: 77 Element Found. How Many Elements You want To Accept: 5 Enter 5 Elements Enter Element 1 : 2 Enter Element 2 : 1 Enter Element 3 : 7 Enter Element 4 : 8 Enter Element 5 : 9 Entered Element are: 2 1 7 8 9 Enter The Element You Want To Search: 10 Element Not Found. */
Write a C Program for implementing Linear search methode using function.
Reviewed by
on
November 16, 2013
Rating: