Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

PROGRAM LINEAR SEARCH

+3 votes
asked Jan 6 by Shivam Kumar Raj (160 points)

#include <stdio.h>

int main()
{
  int array[100], search, c, n;

  printf("Enter number of elements in array\n");
  scanf("%d", &n);

  printf("Enter %d integer(s)\n", n);

  for (= 0; c < n; c++)
    scanf("%d", &array[c]);

  printf("Enter a number to search\n");
  scanf("%d", &search);

for (= 0; c < n; c++)
  {
    if (array[c] == search)    /* If required element is found */
    {
      printf("%d is present at location %d.\n", search, c+1);
      break;
    }
  }
  if (== n)
    printf("%d isn't present in the array.\n", search);

  return 0;
}

1 Answer

0 votes
answered Jan 6 by Peter Minarik (45,000 points)
What is your question?

The program seems to work.

Of course, you can do a bit of optimization here, a bit of better user experience there, etc, but in principle, the logic seems right to me.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...