fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6. /* i & j are for loop counters, temp for swapping, number[] tostore the input numbers in array. You can increase or decrease
  7.   the size of number array as per requirement */
  8.  
  9. int i, j, temp, A[25];
  10.  
  11. printf("Enter the elements you want to sort\n");
  12. for(i=0;i<10;i++)
  13. scanf("%d",&A[i]);
  14.  
  15. // Implementation of insertion sort algorithm
  16. for(i=1;i<10;i++)
  17. {
  18. temp=A[i];
  19. j=i-1;
  20. while((temp<A[j])&&(j>=0))
  21. {
  22. A[j+1]=A[j];
  23. j=j-1;
  24. }
  25. A[j+1]=temp;
  26. }
  27.  
  28. printf("The elements in sorted order: ");
  29. for(i=0;i<10;i++)
  30. printf(" %d",A[i]);
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 4436KB
stdin
Standard input is empty
stdout
Enter the elements you want to sort
The elements in sorted order:  0 0 0 0 0 0 0 0 32767 1800490953