Skip to content

Commit e16abdf

Browse files
authored
Add files via upload
1 parent 6fc5925 commit e16abdf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Insertion Sort.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int i,j,count,temp,num[100];
5+
6+
printf("How many elements?: ");
7+
scanf("%d",&count);
8+
printf("Enter %d elements: ",count);
9+
10+
for(i=0;i<count;i++)
11+
scanf("%d",&num[i]);
12+
for(i=1;i<count;i++)
13+
{
14+
temp=num[i];
15+
j=i-1;
16+
while((temp<num[j])&&(j>=0))
17+
{
18+
num[j+1]=num[j];
19+
j=j-1;
20+
}
21+
num[j+1]=temp;
22+
}
23+
printf("Sorted elements: ");
24+
for(i=0;i<count;i++)
25+
printf(" %d",num[i]);
26+
27+
return 0;
28+
29+
}

0 commit comments

Comments
 (0)