-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.c
More file actions
33 lines (31 loc) · 762 Bytes
/
6.c
File metadata and controls
33 lines (31 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//WAP a program to sort the array elements using Insertion Sort.
#include <stdio.h>
int main()
{
int n, i, j, temp;
int arr[64];
printf("\nEnter Number of Elements:\n");
scanf("%d", &n);
printf("\nEnter %d Integers:\n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
for (i = 1 ; i <= n - 1; i++)
{
j = i;
while ( j > 0 && arr[j-1] > arr[j])
{
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
j--;
}
}
printf("\nSorted list in Ascending Order:\n");
for (i = 0; i <= n - 1; i++)
{
printf("%d\n", arr[i]);
}
return 0;
}