0% found this document useful (0 votes)
32 views2 pages

Practical 6 1

The document describes an insertion sort algorithm that sorts numbers in ascending order. It includes code to prompt the user for the number of elements, accept user input of the elements, and then print out the sorted list of elements.

Uploaded by

Vaibhav Bhagwat
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)
32 views2 pages

Practical 6 1

The document describes an insertion sort algorithm that sorts numbers in ascending order. It includes code to prompt the user for the number of elements, accept user input of the elements, and then print out the sorted list of elements.

Uploaded by

Vaibhav Bhagwat
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
You are on page 1/ 2

Insertion Sort

#include<stdio.h>
void main()
{
int i, j, count, temp, number[25];
clrscr();

printf("How many numbers u are going to enter?: ");


scanf("%d",&count);

printf("Enter %d elements: ", count);


for(i=0;i<count;i++)
scanf("%d",&number[i]);

for(i=1;i<count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])&&(j>=0)){
number[j+1]=number[j];
j=j-1;
}
number[j+1]=temp;
}

printf("Order of Sorted elements: ");


for(i=0;i<count;i++)
printf(" %d",number[i]);

getch();
}
Output:-

How many numbers u are going to enter?: 6


Enter 6 elements: 4
3
8
6
2
1
Order of Sorted elements: 1 2 3 4 6 8

You might also like