c program for strings sorting.........
#include<conio.h>
#include<stdio.h>
#include<string.h> //c program for strings sorting
void main()
{
char a[50][50],cpy[50],t[50];
int l,i,j,n;
clrscr();
printf("enter the limiit\n");
scanf("%d",&n);
printf("String\n");
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=0;i<n;i++)
for(i=0;i<n;i++)
{ if(strcmp(a[i],a[i+1])>0) //compare each strings
{
strcpy(t,a[i]) ;
strcpy(a[i],a[i+1]);
strcpy(a[i+1],t);
}
}
for(i=0;i<n;i++)
{
printf("%s\n",a[i]); //prints sorted string
}
getch();
}
// c program for strings sorting
#include<conio.h>
#include<stdio.h>
#include<string.h> //c program for strings sorting
void main()
{
char a[50][50],cpy[50],t[50];
int l,i,j,n;
clrscr();
printf("enter the limiit\n");
scanf("%d",&n);
printf("String\n");
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=0;i<n;i++)
for(i=0;i<n;i++)
{ if(strcmp(a[i],a[i+1])>0) //compare each strings
{
strcpy(t,a[i]) ;
strcpy(a[i],a[i+1]);
strcpy(a[i+1],t);
}
}
for(i=0;i<n;i++)
{
printf("%s\n",a[i]); //prints sorted string
}
getch();
}
// c program for strings sorting
No comments:
Post a Comment