You are on page 1of 4

#include <stdio.

h>

int main()

int n,j;

printf("Enter number of element in the array :");

scanf("%d",&n);

int arr[n];

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

printf("Enter the element :");

scanf("%d",&arr[j]);

int ele,i;

printf("Enter the element to be searched :");

scanf("%d",&ele);

printf("******************************************************");

printf("\nPress 1 for linear choice");

printf("\nPress 2 for binary choice\n");

int c;

scanf("%d",&c);

printf("******************************************************\n");

if(c==1)

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

printf("%d\n%d\n",arr[i],ele);

if(arr[i] == ele)

printf("Element found at %d position.",i);

goto end;
}

if(c==2)

int start = 0;

int end = n-1;

while(start<=end)

int mid = (start + end)/2;

if(arr[mid] == ele)

printf("Element found at %d",mid);

goto end;

else if(arr[mid]>ele)

end = mid - 1;

else

start = mid + 1;

printf("Element not found.");

end:

{}

return 0;

}
#include <stdio.h>

int main()

int n,i,j,k;

printf("Enter number of element in the array :");

scanf("%d",&n);

int arr[n];

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

printf("Enter the element :");

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

for(j=0;j<n-1;j++)

printf("\nThis is iteration %d.\n",j+1);

for(i=0;i<n-j-1;i++)

if(arr[i]>arr[i+1])

int temp = arr[i];

arr[i] = arr[i+1];

arr[i+1] = temp;

printf("%d got swapped with %d\n",arr[i+1],arr[i]);

printf("The sorted array :\n");

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

printf("%d ",arr[k]);
}

printf("\n");

return 0;

You might also like