Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2014 21:38
Show Gist options
  • Save anonymous/11384819 to your computer and use it in GitHub Desktop.
Save anonymous/11384819 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int value,add,i,n;
printf("How Many Elements To Use: ");
scanf("%d",&n);
int *x = (int*) malloc(n*sizeof(int));
printf("Enter %d Elements: \n",n);
for (i = 0; i<n; i++)
scanf("%d",&x[i]);
for (i = 1; i<=n-1; i++) {
value = x[i];
add = i;
while (i>0 && x[add-1] > value ) {
x[add] = x[add-1];
add--;
}
x[add] = value;
}
for (i = 0; i<n; i++)
printf("%d\n",x[i]);
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment