
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the different searching techniques in C language?
Searching technique refers to finding a key element among the list of elements.
If the given element is present in the list, then the searching process is said to be successful.
If the given element is not present in the list, then the searching process is said to be unsuccessful.
C language provides two types of searching techniques. They are as follows −
- Linear search
- Binary search
Linear Search
- Searching for the key element is done in a linear fashion.
- It is the simplest searching technique.
- It does not expect the list to be sorted.
- Limitation − It consumes more time and reduce the power of system.
Input (i/p)
Unsorted list of elements, key.
Output (o/p)
- Success − If key is found.
- Unsuccessful − Otherwise.
Example
Following is the C program for linear searching technique −
#include<stdio.h> int main (){ int a[50], n, i, key, flag = 0; printf("enter the no: of elements"); scanf ("%d",&n); printf("enter the elements:
"); for (i=0; i<n; i++) scanf( "%d", &a[i]); printf("enter a key element:
"); scanf ("%d", &key); for (i=0; i<n; i++){ if (a[i] == key){ flag = 1; break; } } if (flag == 1) printf("search is successful:"); else printf("search is unsuccessfull:"); return 0; }
Output
When the above program is executed, it produces the following result −
enter the no: of elements5 enter the elements:12 45 13 67 78 enter a key element:67 search is successful:
- Related Articles
- What are string searching functions in C language?
- What are the error handling techniques in C language?
- What are the different operations on files in C language?
- What are the different types of pointers in C language?
- What are the different types of keywords in C language?
- What are different format specifiers used in C language?
- What are different types of constants in C language?
- What are different types of data in C language?
- Explain the sorting techniques in C language
- What Are the Different Isolation and Screening Techniques?
- What are different operators and expressions used in C language?
- What are different pointer operations and problems with pointers in C language?
- Explain the different sections in C language
- Searching data from the different system in SAP.
- Different storage classes in C Language

Advertisements