12 Linear Search Program | C (Programming Language) | Array Data Structure

Please download to get full document.

View again

of 3
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Documents

Published:

Views: 13 | Pages: 3

Extension: DOCX | Download: 0

Share
Related documents
Description
12 Linear Search Program
Transcript
  Linear search c program #include <stdio.h> int main(){ int array[100], search, c, n;  printf(!nter the num er of elements in array \n ); scanf(d,$n);  printf(!nter d inte%er(s) \n , n);  for (c & 0; c < n; c'')  scanf(d, $array[c]);  printf(!nter the num er to search \n ); scanf(d, $search);  for (c & 0; c < n; c'')  { if (array[c] && search)  /* if required element found */   { printf(d is present at location d. \n , search, c'1);    break ;   if (c && n)  printf(d is not present in array. \n , search); return 0;   Linear search for multiple occurrences #include <stdio.h> int main(){ int array[100], search, c, n, count & 0;  printf(!nter the num er of elements in array \n ); scanf(d, $n);  printf(!nter d num ers \n , n);  for ( c & 0 ; c < n ; c'' )  scanf(d, $array[c]);  printf(!nter the num er to search \n ); scanf(d, $search);  for (c & 0; c < n; c'') {  if (array[c] && search) {  printf(d is present at location d. \n , search, c'1);  count'';     if (count && 0)  printf(d is not present in array. \n , search);  else printf(d is present d times in array. \n , search, count);  return 0;    C program for linear search using function #include <stdio.h> lon% linearsearch(lon% [], lon%, lon%);  int main(){ lon% array[100], search, c, n, position;  printf(*nput num er of elements in array \n ); scanf(ld, $n);  printf(*nput d num ers \n , n);  for (c & 0; c < n; c'')  scanf(ld, $array[c]);  printf(*nput num er to search \n ); scanf(ld,$search);  position & linearsearch(array, n, search);  if (position && +1)  printf(d is not present in array. \n , search);  else printf(d is present at location d. \n , search, position'1);  return 0;  lon% linearsearch(lon% a[], lon% n, lon% find) {  lon% c;  for (c & 0 ;c < n ; c'' ) {  if (a[c] && find)  return c;   return +1;  Linear search function using pointers lon% linearsearch(lon% pointer, lon%  n, lon% find) { lon% c;  for (c & 0; c < n; c'') {  if ((pointer'c) && find)  return c;   return +1; 
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks