Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, array[1000], c, d, t, flag = 0;
  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 = 1 ; c <= n - 1; c++) {
  16. t = array[c];
  17.  
  18. for (d = c - 1 ; d >= 0; d--) {
  19. if (array[d] > t) {
  20. array[d+1] = array[d];
  21. flag = 1;
  22. }
  23. else
  24. break;
  25. }
  26. if (flag)
  27. array[d+1] = t;
  28. }
  29.  
  30. printf("Sorted list in ascending order:\n");
  31.  
  32. for (c = 0; c <= n - 1; c++) {
  33. printf("%d\n", array[c]);
  34. }
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement