Search

Tuesday, March 25, 2014
0 comments

C program to sort 10 elements of an array and a list of 11 names in ascending order using selection sort technique

6:27 AMTuesday, March 25, 2014

C program to sort 10 elements of an array in ascending order using selection sort technique.

#include<stdio.h>
#include<conio.h>
void se1_sort_ao(int arr[],int n)
{
  int i, j, min, mops;
  for(i=0;i<n-1;i++)
   {
    min = arr[i]; mpos = 1;
    for(j=i+1; j<n; j++)
    if(arr[j] < min)
      {
      min = arr[j]; mops = j;

      }
    arr[mpos] = arr[i];   arr[i] = min;
   }
}
main()
{
    int a[10], i;
    printf("Enter 10 element of the array:\n \n");
    for(i=0;i<10;i++)
      scanf("%d",&a[i]);
    printf("The array before sorting:\n \n");
    for(i=0;i<10;i++)
      printf("%d",a[i]);
    sel_sort_ao(a,10);
    printf("\n \n The array after sorting:\n \n");
    for(i=0;i<10;i++)
      printf("%d",a[i]);
}

C program to sort a list of 11 names in ascending order using selection sort technique.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void se1sortstrao(char a[][20],int n)
{
  int i, j, mops, k; char min[20];
  for(i=0;i<n-1;i++)
   {
    strcpy( min,a[i]); mpos=i;
    for(j=i+1; j<n; j++)
    if(strcmp(a[j],min)<0)
      {
       strcpy(min,a[j]);   mpos=j;

      }
    strcpy(a[mpos],a[i]);  strcpy(a[i],min);
   }
}
main()
{
    char a[11][20];
    int i;
    clrscr();
    printf("Enter List of 11 names:\n \n");
    for(i=0;i<11;i++)
    gets(a[i]);
    selsortstrao(a,11);
    clrscr();
    printf("The List after sorting:\n \n");
    for(i=0;i<11;i++)
    puts(a[i]);
}
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top