fork download
  1. #include <stdio.h>
  2. int i,j,temp,a[10]= {2,7,6,3,10,9,5,8,4,1};
  3. int main(void) {
  4. int clrscr();
  5.  
  6. /* printing of list before sorting*/
  7. printf("Before sorting=");
  8. printf("[");
  9. for(i=0;i<10;i++)
  10. if((i+1)!=10)
  11. printf("%d, ",a[i]);
  12. else
  13. printf("%d",a[i]);
  14. printf("]");
  15.  
  16. /* logic of bubble sorting*/
  17. for(i=0;i<10;i++)
  18. {
  19. for(j=0;j<10-1-i;j++)
  20. {
  21. if(a[j]>a[j+1])
  22. {
  23. temp=a[j];
  24. a[j]=a[j+1];
  25. a[j+1]=temp;
  26.  
  27. }
  28. }
  29. }
  30.  
  31. /* printing of list after sorting*/
  32. printf("\nAfter sorting=");
  33. printf("[");
  34. for(i=0;i<10;i++)
  35. if((i+1)!=10)
  36. printf("%d, ",a[i]);
  37. else
  38. printf("%d",a[i]);
  39. printf("]");
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 10304KB
stdin
Standard input is empty
stdout
Before sorting=[2, 7, 6, 3, 10, 9, 5, 8, 4, 1]
After sorting=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]