Arranging the word in sequence based on last letter in c program.?
guyzz fast its urgent..?
Answers
Answered by
0
{
char name[10][8], tname[10][8], temp[8];
int i, j, n;
printf("Enter the value of n \n");
scanf("%d", &n);
printf("Enter %d names n", \n);
for (i = 0; i < n; i++)
{
scanf("%s", name[i]);
strcpy(tname[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----------------------------------------\n");
printf("Input NamestSorted names\n");
printf("------------------------------------------\n");
for (i = 0; i < n; i++)
{
printf("%s\t\t%s\n", tname[i], name[i]);
}
printf("------------------------------------------\n");
}
char name[10][8], tname[10][8], temp[8];
int i, j, n;
printf("Enter the value of n \n");
scanf("%d", &n);
printf("Enter %d names n", \n);
for (i = 0; i < n; i++)
{
scanf("%s", name[i]);
strcpy(tname[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----------------------------------------\n");
printf("Input NamestSorted names\n");
printf("------------------------------------------\n");
for (i = 0; i < n; i++)
{
printf("%s\t\t%s\n", tname[i], name[i]);
}
printf("------------------------------------------\n");
}
Answered by
0
#include<stdio.h>
#include<string.h>
int main()
{
char a[10],alpha;
int b;
printf("Enter a word: ");
scanf("%s",a);
b = strlen(a);
for(int i = 0; i < b; i++)
for(int j = 0; j < b; j++)
if(a[j] < a[i])
{
alpha = a[i];
a[i] = a[j];
a[j] = alpha;
}
printf("The reversed word is: %s", a);
return 0;
}
Output:
Enter a word : Sudhajoy
The reversed word is : yusojhda.
Hope it helps!
Similar questions
English,
9 months ago
Environmental Sciences,
9 months ago
Science,
9 months ago
Math,
1 year ago
English,
1 year ago