Friday, August 19, 2011

Program to sort a entered strings using Bubble sort.

//Program to sort a entered strings using Bubble sort.
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char n[10][20],temp[20];
int i,j;
clrscr();
printf("enter the names: ");
for(i=0;i<5;i++)
scanf("%s",&n[i]);
printf("entered names are:");
for(i=0;i<5;i++)
 printf("\n %s",n[i]);
 for(i=0;i<4;i++)
  {
   for(j=0;j<4-i;j++)
    {
     if(strcmp(n[j],n[j+1])>0)
     {
      strcpy(temp,n[j]);
      strcpy(n[j],n[j+1]);
      strcpy(n[j+1],temp);
     }
    }
   }
 printf("sorted names are:");
 for(i=0;i<5;i++)
 printf(" \n%s",n[i]);
 getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More