Tuesday, 8 April 2014

/*write a program to implement selection sort*/
#include<stdio.h>
     /*function for selection sort*/
     void  selection_sort(int arr[],int c)
     {
        printf("****SELECTION SORT****\n\n");
        int i,j,temp;
     printf("\n\n\tUnsorted array is: ");
     for(i=0;i<c;i++)
       {
        printf("%d ,",arr[i]);
       }
     for(i=0;i<c;i++)
       {
     for(j=i+1;j<c;j++)
      {
       if(arr[i]>arr[j])
        {
         temp=arr[i];
         arr[i]=arr[j];
         arr[j]=temp;
        }
      }
     }
     printf("\n\n\tSorted array is: ");
     for(i=0;i<c;i++)
     {
     printf("%d ,",arr[i]);
     }
     }
int main()
{
       int t[50],k,limit,i;
       printf("how many element you want to enter: ");
       scanf("%d",&limit);
       printf("enter the array: ");
       for(k=0;k<limit;k++)
       scanf("%d",&t[k]);
       selection_sort(t,k);

       }
       return 0;

}

No comments:

Post a Comment