Modal Box

Searching

Searching is the process to find if the number to be searched by user exists in the given array or not.                     
 Types of searching are ;
  1. Linear Searching
   2. Binary Searching

Here we will discuss only Linear search.

Program to search an element in the given array

#include <stdio.h>
#include <conio.h>
void main()
{
     int a[10], i=0, ele=0, flag=0;
     printf("enter array elements");
     for(i=0; i<10; i++)
       {
           scanf("%d", &a[i]);
        }
      printf("enter the element to search");
      scanf("%d", &ele);
        
// logic to find the element in the given array.         for(i=0; i<10; i++)           {               if(a[i]==ele)                     {                      flag=1;                      break;                 }             }
        if(flag==1)          printf("element found");         else          printf("element not found"); }

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial