fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int array[100],n=5,c,d,swap;
  6.  
  7. //printf("Enter number of elements\n");
  8. //scanf("%d", &n);
  9.  
  10. printf("Enter %d integers\n", n);
  11.  
  12. for (c=0;c<n;c++)
  13. scanf("%d",&array[c]);
  14.  
  15. for(c=0;c<(n-1);c++)
  16. {
  17. for(d=0;d<(n-c-1);d++)
  18. {
  19. if(array[d]>array[d+1]) /* For decreasing order use < */
  20. {
  21. swap= array[d];
  22. array[d]= array[d+1];
  23. array[d+1]=swap;
  24. }
  25. }
  26. }
  27.  
  28. printf("Sorted list in ascending order:\n");
  29.  
  30. for(c=0;c<n;c++)
  31. printf("%d\n",array[c]);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 9424KB
stdin
5
4
3
2
1
stdout
Enter 5 integers
Sorted list in ascending order:
1
2
3
4
5