C Program to Perform Linear Search For Multiple Occurences of Element inside an Array

If you want to know about “C Program to Perform Linear Search For Multiple Occurences of Element inside an Array” then refer to this article. Let’s go for an article to do this task below.

C Program to Perform Linear Search For Multiple Occurences of Element inside an Array

C Program to Perform Linear Search For Multiple Occurences of Element inside an Array

Source Code

#include <stdio.h>
 
int main()
{
   int array[100], search, c, n, count = 0;
   
   printf("Enter number of elements in arrayn");
   scanf("%d", &n);
   
   printf("Enter %d numbersn", n);
   
   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);
     
   printf("Enter a number to searchn");
   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 isn't present in the array.n", search);
   else
      printf("%d is present %d times in the array.n", search, count);
     
   return 0;
}

Final Thoughts

I hope this article helps you to know about “C Program to Perform Linear Search For Multiple Occurences of Element inside an Array“. We will post new C/C++ project tutorials as soon as possible so stay tuned with us. Don’t forget to bookmark us.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment