0% found this document useful (0 votes)
5 views1 page

C Insertion Sort Program Example

Uploaded by

seouqpubg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

C Insertion Sort Program Example

Uploaded by

seouqpubg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program-1

[Link] a program to implement insertion sort using C Language


#include<stdio.h>
int main()
{
int i,j,n,key,arr[50];
printf("enter the number of element:\n");
scanf("%d",&n);
printf("enter %d element:\n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
//insertion sort
for(j=1;j<n;j++)
{
key=arr[j];
i=j-1;
while((i>=0)&&arr[i]>key)
{arr[i+1]=arr[i];
i=i-1;}
arr[i+1]=key;
}
printf("sorted elements are:\n");
for(i=0;i<n;i++)
printf("%d",arr[i]);
return 0; }

Output:
enter the number of element:
6
enter 0 element:
4
2
3
5
1
6
sorted elements are:
123456

=== Code Execution Successful ===

You might also like