EmbLogic's Blog

C program for sorting an array in asscending order and binary searching

#include
int main()
{
int i,j,a[100],b,n,c,low,mid,high;
printf(“How many no. you want to add in an array:”);
scanf(“%d”,&n);
printf(“Enter element of array:\n”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;ja[j])
{
b=a[i];
a[i]=a[j];
a[j]=b;

}
}
}
printf(“Array after sorting is:\n”);
for(i=0;ia[mid])
{
low=mid+1;
high=n-1;
}
else if(chigh)
{
printf(“%d is not found\n”,c);
break;#include
int main()
{
int i,j,a[100],b,n,c,low,mid,high;
printf(“How many no. you want to add in an array:”);
scanf(“%d”,&n);
printf(“Enter element of array:\n”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;ja[j])
{
b=a[i];
a[i]=a[j];
a[j]=b;

}
}
}
printf(“Array after sorting is:\n”);
for(i=0;ia[mid])
{
low=mid+1;
high=n-1;
}
else if(c
high)
{
printf(“%d is not found\n”,c);
break;
}
}
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>