Showing posts with label ascending order. Show all posts
Showing posts with label ascending order. Show all posts

Monday, October 31, 2011

Sorting the String in Dictionary order

Given an Array of Strings Write a Program to Sort the String in Dictionary Order.


Program:



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[25][25],t[25];
int i,j ,n;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements:\n");
for(i=0;i<n;i++)
scanf("%s",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(a[i],a[j])>0)
{
strcpy(t,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],t);
}
}
}
printf("the sorted array:\n");
for(i=0;i<n;i++)
printf("%s\n",a[i]);
getch();
}
Read full history - Sorting the String in Dictionary order

About Me