0% found this document useful (0 votes)
3 views2 pages

Dsu PR 4

Uploaded by

akashmhatre633
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Dsu PR 4

Uploaded by

akashmhatre633
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//Name: Ashish.s.

jethe

//Roll No:904

//branch:syco

//practical no:4

//practical name:write a c program to search a particular data from the given array of numbers
using

binary search method

//Date:29/07/2024

#include <stdio.h>

#include <conio.h>

int main()

int i, n, mid, first, last, find,a[100];

printf("-----------------------------------\n");

printf("enter the size of an array:");

scanf("%d",&n);

printf("-----------------------------------\n");

printf("Enter the element in asc order:\n" );

for(i=0;i<n;i++)

scanf("%d", &a[i]);

printf("-----------------------------------\n");

printf("Enter Value to be search:" );

scanf("%d",&find);first = 0;

last = n-1;

while (first<=last)

mid =(first + last)/2;

if (a[mid]<find)

{
first=mid + 1;

Else

if(a[mid]==find)

printf("-----------------------------------\n");

printf("element found at index %d\n", mid);

printf("-----------------------------------\n");

break;

else

last=mid-1;

mid=( first + last)/2;

if (first>last)

printf("element not found in the list");

return 0;

You might also like