C Program to search an element in array


In this program, You will learn how to search an element in array in c.


Array list is: 2 3 4 5 6


Example: How to search an element in array in c

Run it Now
#include<stdio.h>

int main() {

   int arr[5], n, f = 0, i;

   printf("Enter 5 Numbers :");
   for (i = 0; i < 5; i++) {
       scanf("%d", &arr[i]);
   }

   printf("\nEnter a Number for Search :");
   scanf("%d", &n);

   for (i = 0; i < 5; i++) {
       if (arr[i] == n) {
           f = 1;
       }
   }

   if (f == 1) {
       printf("\nNumber Found :%d", n);
   } else {
       printf("\nNumber Not Found :%d", n);
   }

   return 0;
}

Output:

Enter 5 Numbers :2 3 4 5 6
Enter a Number for Search :4
Number Found :4