This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View Ada Final Submission (ada Programs) as PDF for free.
Name: Tanmay Baid Roll Number: 0829cs071112 for(i=l1;k
4
Name: Tanmay Baid Roll Number: 0829cs071112
Output How many elements you want to enter in array:-5 Enter the elements of array:5 3 4 2 1 The sorted array is:1 2 3 4 5
5
Name: Tanmay Baid Roll Number: 0829cs071112
Recursive Binary Search #include<stdio.h> #include void main() { int Binsrch(int [],int,int,int); int a[100],i,n,item,res; clrscr(); printf("How many elements:"); scanf("%d",&n); printf("Enter the element of the array:\n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } printf("Enter the element to be searched:"); scanf("%d",&item); res=Binsrch(a,0,n-1,item); if(res==0) printf("The element is not present in the array"); else printf("The element is found at position=%d",res+1); getch(); } int Binsrch(int a[],int i,int l, int x) { int mid; if(l==i) { if(x==a[i])
Iterative Binary Search #include<stdio.h rel="nofollow"> #include void main() { int Binsrch(int [],int,int); int a[100],i,n,item,res; clrscr(); printf("How many elements:"); scanf("%d",&n); printf("Enter the element of the array:\n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } printf("Enter the element to be searched:"); scanf("%d",&item); res=Binsrch(a,n-1,item); if(res==0) printf("The element is not present in the array");