Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int a[100], n, c, d, swap;
  5. printf("Enter number of elements\n");
  6. scanf("%d", &n);
  7. printf("Enter %d integers\n", n);
  8. for (c = 0; c < n; c++)
  9. {
  10. scanf("%d", &a[c]);
  11. }
  12. for (c = 0 ; c< n-1; c++)
  13. {
  14. for (d = 0 ; d < n-c-1; d++)
  15. {
  16. if (a[d]>a[d+1])
  17. {
  18. swap=a[d];
  19. a[d]=a[d+1];
  20. a[d+1]=swap;
  21. }
  22. }
  23. }
  24. printf("Sorted list in ascending order:\n");
  25. for (c = 0; c < n; c++)
  26. {
  27. printf("%d\n", a[c]);
  28. }
  29. return 0;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement