C Program to search an element in the array


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


Array list is: 2 3 4 5 6

Example: How to search an element in the array in c.

#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("Enter a number for search:");
   scanf("%d", &n);

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

   if (f == 1) {
       printf("Number found :%d", n);
   } else {
       printf("Number not found :%d", n);
   }

   return 0;
}

Output:

Enter 5 numbers:10 20 30 40 50                                                                                                         
Enter a number for search:30                                                                                                           
Number found :30