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

Codes For C

The document contains three C programs. The first program performs a linear search for a user-specified element in a predefined array. The second program implements a binary search on the same array, while the third program sorts an array of five user-input integers using the bubble sort algorithm.

Uploaded by

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

Codes For C

The document contains three C programs. The first program performs a linear search for a user-specified element in a predefined array. The second program implements a binary search on the same array, while the third program sorts an array of five user-input integers using the bubble sort algorithm.

Uploaded by

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

#include <stdio.

h>
int main() {
int a[10]={10,20,30,40,50,60,70},i,se,flag=0;
printf("enter search element ");
scanf("%d",&se);
for(i=0;i<10;i++)
{
if(a[i]==se)

{
flag=1;
printf(" element found ");
break;
}
}
if(flag==0)
{
printf("element not found ");

}
return 0;
}
___________________________________________________________________________________
______
#include <stdio.h>
int main() {
int a[10]={10,20,30,40,50,60,70},i,se,l=0,u=9,mid,flag=0;
printf("enter search element ");
scanf("%d",&se);
while(l<=u)

{
mid=(u+l)/2;
if(a[mid]==se)
{
flag=1;
printf("element found");
break;
}
if(se>a[mid])

l=mid+1;
else
u=mid-1;
}
if(flag==0)
{
printf(" element not found ");

}
return 0;
}
___________________________________________________________________________________
______

#include <stdio.h>
int main() {
int a[5],i,j,temp;
printf("enter array elements ");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(i=0;i<4;i++)
{
for(j=0;j<4-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;

}
}
}
printf(" sorted array :");
for(i=0 ; i<5 ; i++)
printf("%d", a[i]);
return 0;
}

You might also like