Tuesday, 8 March 2016

C Program For Insertion Sort In Ascending Order

#include
int main()
{
  //Ghanendra Yadav
  int i,j,s,temp,a[20];

  printf("Enter total elements: ");
  scanf("%d",&s);

  printf("Enter %d elements: ",s);
  for(i=0;i      scanf("%d",&a[i]);

  for(i=1;i      temp=a[i];
      j=i-1;
      while((temp=0))
 {
      a[j+1]=a[j];
          j=j-1;
      }
      a[j+1]=temp;
  }

  printf("After sorting: ");
  for(i=0;i      printf(" %d",a[i]);

  return 0;
}


Output:-



No comments:
Write comments

Recommended Posts × +