0% found this document useful (0 votes)
14 views1 page

Code2flow AoDAQC.code

Uploaded by

web86598
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)
14 views1 page

Code2flow AoDAQC.code

Uploaded by

web86598
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/ 1

Start;

// Step 1: Define and initi


alize the array
int array[10] = {19, 3, 7,
1, 15, 9, 5, 11, 17, 13};
int length = 10; // Length
of the array

// Step 2: Sort the array i


n ascending order using Bub
ble Sort
for (int i = 0; i < length
- 1; i++) {
for (int j = 0; j < len
gth - i - 1; j++) {
if (array[j] > arra
y[j + 1]) {
// Swap array[j
] and array[j + 1]
int temp = arra
y[j];
array[j] = arra
y[j + 1];
array[j + 1] =
temp;
}
}
}

// Step 3: Define variables


for binary search
int start = 0;
int end = length - 1
; // Le
ngth of array - 1
int target;

// Step 4: Input target ele


ment
Print "Enter the target ele
ment to search:";
Read(target);

// Step 5: Perform binary s


earch
while (start <= end) {
int mid = (start + end)
/ 2;

if (array[mid] == targe
t) {
Print("Element foun
d at index:", mid) ;
return;
}
else if (array[mid] < t
arget) {
start = mid + 1; //
Update start
}
else {
end = mid - 1; // U
pdate end
}
}
Print("Element not found.")
;

End;

You might also like