store names and arrange them in ascending order in c
#include <stdio.h>
#include <string.h>
void main()
{
char name[10][20], temp_name[10][20], temp[20];
int i, j, n;
printf("Only the first letter of the name should be in uppercase\n\n");
printf("enter number of names you want to input: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter name %d: ", i +1);
scanf("%s", &name[i]);
strcpy(temp_name[i], name[i]);
}
for (i = 0; i < n - 1 ; i++)
{
for (j = i + 1; j < n; j++)
{
if (strcmp(name[i], name[j]) > 0)
{
strcpy(temp, name[i]);
strcpy(name[i], name[j]);
strcpy(name[j], temp);
}
}
}
printf("\n\nSorted names in ascending alphabetical order\n\n");
for (i = 0; i < n; i++)
{
printf("%s\n", name[i]);
}
}