Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int a[100],temp,k,temp_loc,loc,num,q,i;
- printf("Enter the number of elements = ");
- scanf("%d",&num);
- for(i=0; i<num; i++)
- {
- scanf("%d",&a[i]);
- }
- for(k=0; k<num-1; k++)
- {
- temp = a[k];
- q= k+1;
- printf("K = %d ",k+1);
- for(temp_loc=q; temp_loc<num; temp_loc++)
- {
- if(a[k]>a[temp_loc])
- {
- a[k]=a[temp_loc];
- loc=temp_loc;
- }
- }
- printf("Location = %d ",loc+1);
- a[loc]=temp;
- for(i=0; i<num; i++)
- {
- printf("%d ",a[i]);
- }
- printf("\n");
- }
- printf("Show the sorted array :");
- for(i=0; i<num; i++)
- {
- printf("%d ",a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement