Skip to content

Instantly share code, notes, and snippets.

@krishnaprajapat
Created August 13, 2018 16:45
Show Gist options
  • Save krishnaprajapat/01164e075913563669d21792b4ae6d21 to your computer and use it in GitHub Desktop.
Save krishnaprajapat/01164e075913563669d21792b4ae6d21 to your computer and use it in GitHub Desktop.
Insertion sort using c
#include<stdio.h>
void sort(int a[],int n)
{
int i,j,t;
for(i=1;i<=4;i++){
t=a[i];
for(j=i-1;j>=0&&a[j]>t;j--)
a[j+1]=a[j];
a[j+1]=t;}
for(i=0;i<5;i++)
printf("\n %d",a[i]);
}
int main()
{
int a[5],i;
for(i=0;i<5;i++)
scanf("%d",&a[i]);
sort(a,5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment