#include
#define MAX 30
void bubblesort(int[],int);
main()
{
int arr[MAX],eleM,var;
printf("\n enter the size of array");
scanf("%d",&eleM);
for(var=1;var<=eleM;var++) { printf("\nenter the elements"); scanf("%d",&arr[var]); } printf("sorted array is"); bubblesort(arr,eleM); return 0; } void bubblesort(int arr[],int eleM) { int count,v,var; for(count=0;count<=eleM-1;count++) { for(v=0;v<=eleM-count-1;v++) { if(arr[v]>arr[v+1])
{
var=arr[v];
arr[v]=arr[v+1];
arr[v+1]=var;
}
}
}
for(count=0;count<=eleM-1;count++)
{
printf("\t%d",arr[count]);
}
}
OUTPUT
enter the size of array 6
enter the elements 3
enter the elements 5
enter the elements 1
enter the elements 0
enter the elements 4
enter the elements 6
sorted array is 0 1 3 4 5 6
No comments:
Post a Comment