Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bubble Sort
- #include<stdio.h>
- #include<conio.h>
- void bubble(int[], int);
- void main()
- {
- clrscr();
- int n, array[15];
- printf("Enter number of element of array::");
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- scanf("%d",&array[i]);
- bubble(array,n);
- getch();
- }
- void bubble(int arr[], int num)
- {
- int i,j,k,temp;
- printf("UnSorted Array is ::\n");
- for(k=0;k<num;k++)
- printf("%2d",arr[k]);
- for(i=1;i<num;i++)
- {
- for(j=0;j<num-1;j++)
- {
- if(arr[j]>arr[j+1])
- {
- temp = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = temp;
- } //if end
- } //inner for loop j wala
- }
- //outer for loop
- printf("\nsorted array is::\n");
- for(k=0;k<num;k++)
- printf("\n\t%d", arr[k]);
- }
Advertisement
Add Comment
Please, Sign In to add comment