Docsity

Arrays and Searching Techniques in C: Sequential and Binary Search Algorithms, Slides of Object Oriented Programming

Partial preview of the text

Download Arrays and Searching Techniques in C: Sequential and Binary Search Algorithms and more Slides Object Oriented Programming in PDF only on Docsity!

** PRESENTED BY

PRESENTED BY

* Program

#include<conio.h> #include int main() { using namespace std; int marks[10]; for(int i=0;i<10;i++) { cout<<"Enter marks"<<endl; cin>>marks[i]; } cout<<"The marks of the student are"<<endl; for(int i=0;i<10;i++) { cout<<marks[i]<<endl; } getch(); return 0; }

* Searching in

Arrays

*Searching is a process of finding the

required data in the array.

*Searching becomes more important when

the length of the array is very large.

*Two types to search an array.
*1:-Sequential search
*2:-Binary search
*If the value of array matches with the desired value,

the search is complete.

*If the value of array does not match , move to next

element and repeat same process.

** Program

Program

*#include<conio.h> *#include *int main() *{

  • using namespace std; *int arr[10]={10,20,30,40,50,60,70,80,90,100}; *int i,n,loc=-1; *cout<<"Enter value to find:"; *cin>>n; *for(i=0;i<10;i++)
  • if(arr[i]==n)
  • loc=i; *if(loc==-1)
  • cout<<"value not found in the array."; *else
  • cout<<"value found at index\t"<<loc; *getch(); *return 0; *}

**Program

Program

*#include *#include<conio.h> *int main() *{

  • using namespace std; *int arr[10]={10,20,30,40,50,60,70,80,90,100}; *int n,i,mid,start,end,loc; *loc=-1; *start=0; *end=9; *cout<<"Enter any number to find:"; *cin>>n;

* ANY

QUESTION

* ANY

QUESTION

**THANK YOU

THANK YOU