Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void input(int a[], int &n)
- {
- printf("Enter the size of Array : ");
- scanf("%d",&n);
- for (int i=0; i<n; i++)
- {
- printf("Enter the member %d : ", i);
- scanf("%d",&a[i]);
- }
- }
- void SelectionSort(int a[], int n)
- {
- int min;
- for(int i=0;i<n-1;i++)
- {
- min=i;
- for(int j=i+1;j<n;j++)
- if(a[j]<a[min]) min=j;
- int temp = a[i];
- a[i] = a[min];
- a[min] = temp;
- }
- }
- void output(int a[], int n)
- {
- for(int i=0; i<n; i++)
- printf("%5d",a[i]);
- printf("\n");
- }
- int main()
- {
- int a[1000], n;
- input(a,n);
- printf("Array inputed : \n");
- output(a,n);
- SelectionSort(a,n);
- printf("Array sorted: \n");
- output(a,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement