Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # Program to sort elements in Ascending Order using Insertion Sort in C language

• 0
• 0
• 0
• 0
• 0
• 0
• 1
• 0
• 306
Comment on it

Program to sort elements in Ascending Order using Insertion Sort in C language

Insertion Sort
Definition:- It is a sorting which sort one number at a time & insert to its proper location in the array list until all the numbers are sorted from the list.

```//Header Files
#include<stdio.h>
#include<conio.h>

void main()
{
int n, i, k, ptr, temp, arr[20];
clrscr();            //to clear screen
// User to input the limit of the array
printf("\n Enter the Element limit:-");
scanf("%d",&n);                // To scan the limit of the array
//Asking user to input the elements of the array
printf("\n Enter the element to be sorted:->\n");
for(i=0;i<n;i++){
scanf("%d", &arr[i]);  //Scanning the elements in the array
}
// inserting the element in the correct place in the array
for(k=1; k<n;k++){
temp = arr[k];
ptr = k-1;
while((temp<arr[ptr]) && (ptr>=0)) {
arr[ptr+1] = arr[ptr];
ptr = ptr-1;
}
arr[ptr+1] = temp;
}

printf("\n Insertion sorted elements are:-");
for(i=0;i<n;i++)
{
printf("\n%d",arr[i]);  //Printing the Sorted array
}
getch();
}
```

Output:-

```Enter the Element limit:-6

Enter the element to be sorted:->
9
5
7
0
2
4

Insertion sorted elements are:-
0
2
4
5
7
9
```

## 0 Comment(s)

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:
Fill out the form below and reset your password:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Use Online Project Management Tools for Free
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Record & Share

### Desktop Recording Tool

• All at 0 Cost ....
• Online tool for Recording Desktop Activity and Audio
• Store and Share from the Cloud
• Creating Software Product Demos
• Creating video tutorials
• Recording and Reporting Software and Project issues as videos
• Ask Tech Query
• Post Blogs