/*Serial No.108 [swami85.cpp]*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int i,j,k;
char name[10][10],tname[10][10],temp[10];
clrscr();
printf("How many numbers you want to store:=");
scanf("%d",&k);
printf("Enter numbers for in an array:=");
fflush(stdin);
for(i=0;i<k;i++)
{
scanf("%s",name[i]);
strcpy(tname[i],name[i]);
}
for(i=1;i<k;i++)
{
for(j=1;j<k;j++)
{
if(strcmpi(name[j],name[j-1])<0)
{
strcpy(temp,name[j-1]);
strcpy(name[j-1],name[j]);
strcpy(name[j],temp);
}
}
}
printf("The sorted names in alphabetical order [A to Z Format] are:\n");
printf("\tOldlist\t\tNew list\n\n");
for(i=0;i<k;i++)
{
printf("\t%s\t\t%s\n",tname[i],name[i]);
}
printf("\n\nThe sorted names in [Z to A Format] are:\n");
for(i=k-1;i>=0;i--)
{
printf("\t%s\n",name[i]);
}
getch();
}
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int i,j,k;
char name[10][10],tname[10][10],temp[10];
clrscr();
printf("How many numbers you want to store:=");
scanf("%d",&k);
printf("Enter numbers for in an array:=");
fflush(stdin);
for(i=0;i<k;i++)
{
scanf("%s",name[i]);
strcpy(tname[i],name[i]);
}
for(i=1;i<k;i++)
{
for(j=1;j<k;j++)
{
if(strcmpi(name[j],name[j-1])<0)
{
strcpy(temp,name[j-1]);
strcpy(name[j-1],name[j]);
strcpy(name[j],temp);
}
}
}
printf("The sorted names in alphabetical order [A to Z Format] are:\n");
printf("\tOldlist\t\tNew list\n\n");
for(i=0;i<k;i++)
{
printf("\t%s\t\t%s\n",tname[i],name[i]);
}
printf("\n\nThe sorted names in [Z to A Format] are:\n");
for(i=k-1;i>=0;i--)
{
printf("\t%s\n",name[i]);
}
getch();
}
No comments:
Post a Comment
If you have any doubt, feel free to ask...