Name Sort

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<string.h>
#define SIZE 5
#define LEN 10
int main(void)
{
char names[SIZE][LEN], temp[LEN];
int i,j;
printf("\n Enter Names:: ");
for (i = 0; i < SIZE; i++)
{
printf("\n names[%d]", i);
fflush(stdin);
gets(names[i]);
}
printf("\n Names are:: ");
for (i = 0; i < SIZE; i++)
{
printf("\n %s", names[i]);
}
for (i = 0; i < SIZE; i++)
{
for (j = 0; j <SIZE-i-1; j++)
{
if (strcmp(names[j], names[j+1])<0)
{
strcpy(temp, names[j]);
strcpy(names[j], names[j+1]);
strcpy(names[j+1],temp);
}
}
}
printf("\n Names after desc sort ::\n ");
for (i = 0; i < SIZE; i++)
{
printf("\n %s", names[i]);
}
return 0;
}

You might also like