#include<stdio.h>
int main()
{
int arr[10],i,max=0;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
max=arr[0];
for(i=1;i<10;i++)
{
if(max<arr[i])
max=arr[i];
}
printf("Maximum value of Array: %d",max);
return 0;
Minimum value of Array
#include<stdio.h>
int main()
{
int arr[10],i,min=0;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
min=arr[0];
for(i=1;i<10;i++)
{
if(min>arr[i])
min=arr[i];
}
printf("Minimum value of Array: %d",min);
return 0;
}
Linear Search in Array
#include<stdio.h>
int main()
{
int arr[10],i,value,index;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
printf("\nEnter a value to be searched: ");
scanf("%d",&value);
index = -1;
for(i=0;i<10;i++)
{
if(arr[i]==value)
{
index=i;
break;
}
}
if(index>=0)
printf("Value found in Array at %d location",index);
else
printf("Value not found in Array");
return 0;
}
Binary Search
#include<stdio.h>
int main()
{
int arr[10],i,max,min,mid,val,index;
printf("Please enter 10 values in ascending order:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
printf("\nEnter a value to be searched: ");
scanf("%d",&val);
max=9;
min=0;
index=-1;
while(min<=max)
{
mid=(max+min)/2;
if(val==arr[mid])
{
index=mid;
break;
}
if(arr[mid]>val)
max=mid-1;
else
min=mid+1;
}
if(index>=0)
printf("Value found in Array at %d location",index);
else
printf("Value not found in Array");
return 0;
}
Bubble Sort
#include<stdio.h>
int main()
{
int arr[10],i,j,t;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if (arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);
return 0;
}
Selection Sort
#include<stdio.h>
int main()
{
int arr[10],i,j,k,t;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i++)
{
k=i;
for(j=i;j<10;j++)
{
if(a[k]>a[j])
k=j;
}
if(k!=i)
{
t=a[k];
a[k]=a[i];
a[i]=t;
}
}
printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);
return 0;
}
Insertion Sort
#include<stdio.h>
int main()
{
int arr[10],i,j,new;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=1;i<10;i++)
{
new=a[i];
for(j=i-1;j>=0&&new<a[j];j--)
{
a[j+1]=a[j];
}
a[j+1]=new;
}
printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);
return 0;
}
Just Give Your Feedback ConversionConversion EmoticonEmoticon