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