#include <stdio.h>
#include <conio.h>
int main()
{
 int array[100], n, i, j, position, temp;
 clrscr();
 printf("Enter number of elements : \n");
 scanf("%d", &n);

 printf("Enter %d integers\n", n);

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

 for (i=0;i<(n-1);i++)
 {
 position = i;

 for (j=i+1;j<n;j++)
 {
 if ( array[position] > array[j] )
 position = j;
 }
 if ( position != i )
 {
 temp = array[i];
 array[i] = array[position];
 array[position] = temp;
 }
 }

 printf("Sorted list in ascending order:\n");

 for (i=0;i<n;i++)
 printf("%d\n", array[i]);
 getch();
 return 0;
}
OUTPUT
Enter number of elements : 5
Enter 1 element :
 40 
 10 
 30 
 60 
 20 
Sorting list ascending order : 
 10
 20
 30
 40
 60

Leave a Reply

Subscribe to Posts | Subscribe to Comments

All Notes on BCA

All Notes  on BCA
BCA all subjects notes

Total Pageviews

Translate

Powered by Blogger.

Copyright © All Notes on BCA