0% found this document useful (0 votes)
2 views3 pages

Code

The document contains a C program that implements binary search and selection sort algorithms. It defines functions for searching an element in a sorted array and sorting an array of integers. The main function takes user input for the size of the array and the elements, then performs a binary search for a specified number and displays the sorted array.

Uploaded by

vip10121315
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)
2 views3 pages

Code

The document contains a C program that implements binary search and selection sort algorithms. It defines functions for searching an element in a sorted array and sorting an array of integers. The main function takes user input for the size of the array and the elements, then performs a binary search for a specified number and displays the sorted array.

Uploaded by

vip10121315
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

#include<stdio.

h>

int tim(int a[],int n,int x){

int l=1;

int r=n;

int m;

while(l<=r){

m=(l+r)/2;

if(x<a[m]){

r=m-1;

}else if(x>a[m]){

l=m+1;

}else{

return m;

int nhiphan(int l,int r int a[],int x,int n){

int loc;

int m;

int l=1;

int r=n;

if(l>r){

loc=0;

}else{

m=(l+r)/2;

}
if(x<a[m]){

loc=nhiphan(a,x,n);

}else if(x>a[m]){

loc=nhiphan(a,x,n);

}else{

loc=m;

printf("so can tim la: %d\n",loc);

void sapxep(int a[],int n){

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

int min=i;

for(int j=i+1;j<n;j++){

if(a[j]<a[min]){

min=j;

int c=a[i];

a[i]=a[min];

a[min]=c;

int main(){

int a[100],n;

int x;

printf("nhap n: ");
scanf("%d",&n);

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

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

int l=1,r=n;

printf("nhap so can tim:");

scanf("%d",&x);

nhiphan(a,x,n);

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

printf("%d ",a[i]);

return 0;

You might also like