answersLogoWhite

0

If you are using the String class to store your names then you can use the < or > operators to compare the order, alphabetically, they appear in.

String names[3];

int numberOfNames = 3;

names[0] = "abc";

names[1] = "dfg";

names[2] = "hij";

printf("befores%s\n", names[0],names[1],names[2]);

for( int i = 0; i < numberOfNames-1; i++ )

{

for( int j = 0; j < numberOfNames; j++ )

{

if( names[j] < names[j+1] )

{

names[j].swap( names[j+1] );

}

}

}

printf("afters%s\n", names[0],names[1],names[2]);

output:

before abcdfghij

after hijdfgabc

*********************************************************************

this will give correct answer

#include

int main(){

int i,j,n;

char str[20][20],temp[20];

puts("Enter the no. of string to be sorted");

scanf("%d",&n);

for(i=0;i<=n;i++)

gets(str[i]);

for(i=0;i<=n;i++)

for(j=i+1;j<=n;j++){

if(strcmp(str[i],str[j])>0){

strcpy(temp,str[i]);

strcpy(str[i],str[j]);

strcpy(str[j],temp);

}

}

printf("The sorted string\n");

for(i=0;i<=n;i++)

puts(str[i]);

return 0;

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

To write a polynomial in standard form write the exponents of the in descending order?

Terms


Give two paragraph descending order?

First, decide on the paragraphs that you would like to use. Write them out in the descending order that you want.


Write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student?

write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student.


How do you write polynomials in ascending and descending order?

before and after use an conpair the results


When writing polynomial's in standard form what do you write in descending order?

Powers of their exponents


Write each factor as a polynomial in descending order x2 plus 14x plus 24?

The polynomial IS written in descending order.


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Write an Assembly language program which implements sorting algorithm both ascending and descending order and display those numbers with certain delay say of 5sec between successive displays?

das


Write each polynomial in descending order 36a2-49b2?

(6a + 7b)(6a - 7b)


Write a c programme to print all the even numbers in descending order?

#include(stdio.h) int main ()


How do you write each factor as a polynomial in descending order x3-3x2-10x?

x(x + 2)(x - 5)


Write 8x2 plus 6x - 35 as a polynomial in descending order?

Type your answer here... (2x + 5)(4x - 7)