rajamit872

Bubble Sort

Aug 6th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. //Bubble Sort
  2.  
  3. #include<stdio.h>
  4. #include<conio.h>
  5. void bubble(int[], int);
  6. void main()
  7. {
  8. clrscr();
  9. int n, array[15];
  10. printf("Enter number of element of array::");
  11.  
  12. scanf("%d",&n);
  13.  
  14. for(int i=0;i<n;i++)
  15. scanf("%d",&array[i]);
  16. bubble(array,n);
  17. getch();
  18. }
  19.  
  20. void bubble(int arr[], int num)
  21. {
  22. int i,j,k,temp;
  23. printf("UnSorted Array is ::\n");
  24. for(k=0;k<num;k++)
  25. printf("%2d",arr[k]);
  26.  
  27. for(i=1;i<num;i++)
  28. {
  29. for(j=0;j<num-1;j++)
  30. {
  31. if(arr[j]>arr[j+1])
  32. {
  33. temp = arr[j];
  34. arr[j] = arr[j+1];
  35. arr[j+1] = temp;
  36. } //if end
  37. } //inner for loop j wala
  38. }
  39.  
  40. //outer for loop
  41. printf("\nsorted array is::\n");
  42. for(k=0;k<num;k++)
  43. printf("\n\t%d", arr[k]);
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment