Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views4 pages

DAA Assignment (P)

Uploaded by

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

DAA Assignment (P)

Uploaded by

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

Design and analysis of algorithms[p]

Practical Assignment 1

Csl0559[p]

Submitted By: Anik Palit (BETN1CS18015)

Submitted to: Krishna Kumar Joshi (Asst Prof (CS&A)

Date of Submission:23rd September


#include <stdio.h>

#include <conio.h>

void main()

int c, first , last, middle, n, search, A[10];

clrscr();

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n" , n);

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

scanf("%d" ,&A[c]);

printf("Enter value to find\n");

scanf("%d" ,&search);

first = 0;

last = n - 1;

middle = (first+last)/2;

while( first <= last )

if( A[middle] < search )

first = middle + 1;
else if ( A[middle] == search )

printf("%d found at location %d .\n", search, middle+1);

break;

else

last = middle - 1;

middle = ( first + last )/2;

if ( first> last )

printf("Not found! %d is not present in the list .\n;", search);

getch();

You might also like