/* insertion sort ascending order */
#include <stdio.h>
void main()
{
int n, arr[20], c, d, t;
printf("Enter 20 integers\n", n);
for (c = 0; c < 20; c++) {
scanf("%d", &arr[c]);
}
for (c = 1 ; c <= 19; c++) {
d = c;
while ( d > 0 && arr[d] < array[d-1]) {
t= arr[d];
arr[d]= arr[d-1];
arr[d-1]= t;
d--;
}
}
printf("Sorted list in ascending order:\n");
for (c = 0; c <= 19; c++) {
printf("%d\n", arr[c]);
}
getch();
}
#include <stdio.h>
void main()
{
int n, arr[20], c, d, t;
printf("Enter 20 integers\n", n);
for (c = 0; c < 20; c++) {
scanf("%d", &arr[c]);
}
for (c = 1 ; c <= 19; c++) {
d = c;
while ( d > 0 && arr[d] < array[d-1]) {
t= arr[d];
arr[d]= arr[d-1];
arr[d-1]= t;
d--;
}
}
printf("Sorted list in ascending order:\n");
for (c = 0; c <= 19; c++) {
printf("%d\n", arr[c]);
}
getch();
}
No comments:
Post a Comment