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

Insertion Sort

The provided C program sorts an array of integers using a modified insertion sort algorithm. It prompts the user to input the number of elements and the elements themselves, then sorts the array while displaying the state of the array after each pass. The program utilizes standard input/output functions and includes a clear screen function, though it may not compile on all systems due to the use of 'conio.h'.
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)
23 views2 pages

Insertion Sort

The provided C program sorts an array of integers using a modified insertion sort algorithm. It prompts the user to input the number of elements and the elements themselves, then sorts the array while displaying the state of the array after each pass. The program utilizes standard input/output functions and includes a clear screen function, though it may not compile on all systems due to the use of 'conio.h'.
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:

#include <stdio.h>
#include<conio.h>

int main()
{
int i,j,n,temp,k,m;
int arr[100];
clrscr();
printf("Enter number of elements you want to insert:\n");
scanf("%d",&n);
printf("Enter array elements:");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n-1;i++)
{
j=i+1;
for(m=i;m>=0;m--)
{
temp=arr[m];
if(arr[m]>arr[j])
{
arr[m]=arr[j];
arr[j]=temp;
j=m;
}
}
printf("\n Pass %d :",i+1);
for(k=0;k<n;k++)
{
printf("%d\t",arr[k]);
}
}
getch();
return 0;
}
OUTPUT:

You might also like